Flush just an app not the whole project

前端 未结 4 460
感动是毒
感动是毒 2021-02-04 01:08

python manage.py flush removes data from the entire project. I would like to be able to do python manage.py flush agivenapp How can I do this?

4条回答
  •  后悔当初
    2021-02-04 01:47

    For later versions of Django try in the Django shell:

    from django.apps import apps
    my_app = apps.get_app_config('my_app_name')
    my_models = my_app.get_models()
    for model in my_models:
        model.objects.all().delete()
    

    More on the apps module can be found here. Of course, you could convert this to a management command yourself using the management infrastructure.

提交回复
热议问题