[Fixed]-Django : Recreating all the tables for app in Django 1.9 version

1👍

You are applying an initial migration, which means that you are creating the first version of that app’s tables.

But you already have that table in the database so you can fake the initial migration

python manage.py migrate --fake-initial

The –fake-initial flag to migrate was added in Django 1.8. Previously, Django would always automatically fake-apply initial migrations if it detected that the tables exist.

But note that this only works given two things:

  1. You have not changed your models since you made their tables (which you have).
  2. You have not manually edited your database.

So you can’t fake them either.

  • I Want to use the current database

    If you have your previous unaltered version of initial migration files of the testapp with migration(non-initial) files with your changes, you can use them for migration.

    First fake that initial migration and then apply your changes
    (This may be tricky now, as you also have to truncate django_migrations table that stores migrations data)

  • I can start from scratch –

    No Problem (drop your database) as its an initial migration and that’s what they are for – Create DB/Table.

0👍

If you already have tables in your db, try ./manage.py flush to clear all data. Flush carries out the SQL Drops on the entire db.

If you want to delete the db, drop the mysql db. Create another mysql db with the same name. Then run ./manage.py makemigrations followed by ./manage.py migrate to recreate the tables in the db.

👤him229

Leave a comment