1

I want to remove all data from all models defined in a single Django app. The number of models might change in the app, hence I don't want to hard code model names. It would be great if it might be done using manage.py command, however I was not able to find one.

The manage.py flush command is not suitable, because it only allows to clear data from all apps.

niekas
  • 8,187
  • 7
  • 40
  • 58

1 Answers1

3

If you are using django version greater than 1.7, which you are. You can simply use migrate zero command to drop from specific app. Like:

py manage.py migrate APPNAME zero

Here, APPNAME is name of the app from where you want to flush data. Refs

Biplove Lamichhane
  • 3,995
  • 4
  • 14
  • 30
  • `manage.py migrate APPNAME zero` and then `manage.py migrate APPNAME` does the job. The tables of an app are dropped and recreated. – niekas May 08 '20 at 04:48