Django: Flush (Clear) Database

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.

Django 1.4

On earlier versions of Django, you could use “reset ” for removing tables from a particular app.

DEPRECATED: The command is deprecated and newer versions use the flush command. Check out the Django manual for more details.


3 Comments Django: Flush (Clear) Database

  1. Tanvir

    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 😀

    Reply
  2. Victor

    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.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *