Django Unable To Migrate Postgresql: Constraint X Of Relation Y Does Not Exist
I'm trying to run a Django 1.11 migration on a PostgreSQL 9.6.5 database, and I'm getting the odd error: Applying myapp.0011_auto_20171130_1807...Traceback (most recent call last
Solution 1:
The problem turned out to be that I converted the database to PostgreSQL from MySQL using the tool pgloader, and this tool converts constraints by creating them as indexes in PostgreSQL, whereas the Django PG backend creates them as constraints. So when the migration runs, it only looks for constraints and doesn't find any.
I fixed this by dropping the index and re-creating it as a true constraint with:
DROP INDEX idx_32269_myapp_mymodel_title_333195ae82ac2107_uniq;
ALTERTABLE public.myapp_mymodel ADDCONSTRAINT idx_32269_myapp_mymodel_title_333195ae82ac2107_uniq UNIQUE(title);
After that, the Django migration ran correctly.
Post a Comment for "Django Unable To Migrate Postgresql: Constraint X Of Relation Y Does Not Exist"