[Fixed]-Migrating to existing database without matching migration

1👍

Django thinks the migrations have already been run because there are entries for the migrations in the django_migrations table. That is where django registers the migrations that have already been completed. You need to go into postres and delete the rows for those migrations you do not want. This is assuming you db schema matches your models.py. If there is a difference you need to manually edit the migration files to remove any discrepancies, or modify you models.py temporariliy to match up.

psql [db name]
delete from django_migrations;

Now delete all migrations folders in your apps and run:
./manage.py migrate –fake-initial

If your models.py or migrations were edited to match the current db schema and you now want to run a migration on the differences, run ./manage.py makemigrations and then migrate

Also look here: Django 1.8: Create initial migrations for existing schema

Leave a comment