Chaos
Chaos

Reputation: 471

Django Rebuild all migrations

I am building an app in Django and it uses a live/in-use database.

Basically since the apps development the SQL Database has undergone some structure changes and it is causing issues with Django, Django will try to apply migrations to the database that already exist. For example:

In the Django app I marked the email column as unique which was fine based on the development database. However the main database now always has a table change that marks the email column as unique. Django is fighting this unique key with the one that already exists.

So is it possible to clear all Django migrations and have it make migrations again compared to the more up to date SQL database structure?

Upvotes: 3

Views: 3796

Answers (1)

YPCrumble
YPCrumble

Reputation: 28662

If your models are very out of sync with your database, the easiest option is probably to rebuild your models from scratch using inspectdb.

If your models are pretty close to the database already, the first step is to make sure that your models match the database exactly. You can use sqldiff from django-extensions for this.

Once your Django models match your database, follow this answer to re-create migrations based on the existing database schema.

Upvotes: 1

Related Questions