Stuck in a django migration IntegrityError loop: can I delete those migrations that aren't yet in the db?
<p>So, I committed and pushed all my code, and then deployed my web application successfully. Then, I added a new model to my 'home' app, which (for a reason I now understand, but doesn't matter here), created an <code>IntegrityError</code> (<code>django.db.utils.IntegrityError: insert or update on table "foo" violates foreign key constraint "bar"</code>). I ran <code>python manage.py makemigrations</code>, <code>python manage.py migrate</code>, which causes the the <code>IntegrityError</code>.</p>

<p>However, even if I remove all of my new model code(so that git status comes up with nothing), the IntegrityError still happens. If I connect to my db via a different python instance and download <code>select * from django_migrations;</code>, the latest db migration: <strong>0020</strong> there is eight migrations away from my latest local <code>home/migrations</code> migration file: <strong>0028</strong>.</p>

<p>--> My question is: is it safe for me to delete my local <strong>0021-0028</strong> migration files? Will this fix my problem?</p>

<p>OK, so I crossed my fingers, backed my local 0021-0028 migration files, and then deleted them. <strong>It worked</strong>. I think they key is that the migration files were not yet in the database yet, but not 100% sure. +1 if anyone can answer further for clarification.</p>

python django