Troubleshooting Constraint Already Exists

45 views
Skip to first unread message

jason...@gmail.com

unread,
Feb 9, 2018, 3:17:19 PM2/9/18
to Django users
Hello all,

I'm using 1.11 and have a migration that is throwing:

django.db.utils.ProgrammingError: constraint "inventory_ltmvirtualserver_ltm_id_47dc1635_fk" for relation "inventory_ltmvirtualserver" already exists

I'm having troubles figuring this out for a couple reasons.  First, the migration scripts ran fine against the development and stage environments and only fails in production.  Also, if I export the production database and import that copy to the development environment the migration works just fine.

The other issue I'm having is that the migration in question (inventory.0040_auto_20180104_1225) doesn't actually reference the "ltmvirtualserver" model.  I can't figure out why the migration is attempting to create this constraint.

The backend database is Postgres.

What information can I provide to help track this down?  Migration scripts?  Is there a way to get the precise line in the migration script that is being processed when the error is thrown?

Thanks in advance for the help.

j

jason...@gmail.com

unread,
Feb 9, 2018, 5:03:27 PM2/9/18
to Django users
I was able to work around the issue by dumping out the SQL for the migration that was failing (manage.py sqlmigrate ...) and running through the steps manually (skipping the "already exists" constraints) and finally marking the migration as completed (with a --fake).

j
Reply all
Reply to author
Forward
0 new messages