-
Notifications
You must be signed in to change notification settings - Fork 12
What to do with missing migration files
This page is intended for Wessel to document how to solve a complicated database problem, and for potential other developers that run into the same problem.
The Django models have been expanded, and the database needs to reflect this. This can normally be achieved with the instructions here: https://github.com/Woseseltops/signbank/wiki/Developer-guide#adjusting-models .
Because of some syncing problems between various workspaces, various migration files have been lost. In the hypothetical situation that all of the problems were caused in one week, you could summarize the problem as follows:
- The migration files are still as they were Monday
- The database structure is still as it was Tuesday
- The Django models were changed on Wednesday
Normally, you would use Django South to update the database structure to match Wednesday's code, but this is prevented by the fact that the migration files are even further behind.
Build the migration files from scratch. Steps to achieve this:
- Back up everything.
- Go back to a commit where the models match the database from Tuesday. This way, the only discrepancy is between the the migration files and the database. This assumes the database is not under version control.
- Delete all migration files.
-
python manage.py schemamigration <app-name> --initial
This creates a new migration matching the current database models. -
python manage.py migrate <app-name> 0001 --fake --delete-ghost-migrations
Officially installs your new migration. In reality, because the migration matches the current database structure exactly, it will only throw away information on past migrations. The resulting database will think it was created from that one initial 0001 migration. - Save the migration file somewhere else.
-
git checkout master
to go back to Wednesday's code, and replace the previous migration files with the newly created migration file. The migration files and database structure are now both on Tuesday, the code is on Wednesday. - The regular procedure to update a database.