niekas
niekas

Reputation: 9117

How to clear all data from an app in Django?

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.

Upvotes: 1

Views: 2251

Answers (1)

Biplove Lamichhane
Biplove Lamichhane

Reputation: 4095

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

Upvotes: 4

Related Questions