In Django, we often need to remove all the tables (with data) and recreate them from scratch. Specially, after changing a model structure, if we’re not using any database migration tool, we usually manually drop the table and run syncdb again. But there’s a quick way –
Django 1.5 and Higher
We have to collect the output of sqlclear and then pass it to dbshell.
1 |
./manage.py sqlclear <appname> | ./manage.py dbshell |
Django 1.4
On earlier versions of Django, you could use “reset
1 |
python manage.py reset <appname> |
DEPRECATED: The command is deprecated and newer versions use the flush command. Check out the Django manual for more details.
3 replies on “Django: Flush (Clear) Database”
thanks ,
today ,
i fall this problem ,
thanks for this post 😀
i am using django 1.6 and this command not working
“./manage.py sqlclear <appname> | ./manage.py dbshell”
i reset my db by this
python manage.py sqlclear <appname> | python manage.py dbshell
then
migrate the db
thanks for the post 😀
I tried all sort of things, I found easier removing sqlite3 file, then to going into the “migrations” path/folder, e.g. /project/app/migrations, which has all the migrations of the project. You can delete (or backup) all of these files and create a new makemigrations file, which will be initial.