Search code examples
pythondjangomodelmigration

I can't just delete the db django.db.migrations.exceptions.InconsistentMigrationHistory


I know that there are similar questions on the stackoverflow, however, I can’t just take and erase the database and create it again important data is stored there, I think it’s about the migrations themselves, if you have a solution to this problem, I will be very glad to hear it:

python manage.py migrate

raise InconsistentMigrationHistory( django.db.migrations.exceptions.InconsistentMigrationHistory: Migration members.0001_initial is applied before its dependency company_directory.0002_initial on database 'default'.


Solution

  • It seems to be an error in your migrations files. You can enter it in the migrations folder so delete everything except init.py then you can make the "python manage.py makemigrations" again and your error should be solved. This is dangerous because if you make some mistake it can make your application stop working, but if you have errors in your migrations files this is the only way I know.

    To be sure you do not delete anything wrong you can create an backup of your migrations folder or all your project before test it.

    This will not affect your database, just your migrations files.