Ticket #1058 (closed defect: worksforme)

Opened 2 years ago

Last modified 2 years ago

PostreSQL issues with alter commands

Reported by: segnalazioni@… Owned by: andrew
Priority: major Milestone: 1.0
Component: migrations Version: mercurial
Keywords: Cc:

Description

Applying migrations that involves alter_column on foreign keys or alter_tables fail.

db.alter_column('categories_category', 'parent_id', self.gf('mptt.fields.TreeForeignKey')(null=True, to=orm['categories.Category']))

from django-categories 1.0.3 fails with

FATAL ERROR - The following SQL query failed: ALTER TABLE "categories_category" ADD CONSTRAINT "parent_id_refs_id_26f7e8d2e85f846b" FOREIGN KEY ("parent_id") REFERENCES "categories_category" ("id") DEFERRABLE INITIALLY DEFERRED;
The error was: constraint "parent_id_refs_id_26f7e8d2e85f846b" for relation "categories_category" already exists

It looks like _fill_constraint_cache() method in DatabaseOperations?() fill the cache with both the foreign key and the related key, so that _find_foreign_constraints cannot find the involved constraint.

Renaming table also fails

db.rename_table("text_text", "cmsplugin_text")

from django-cms 2.2 (migration is actually in application plugins.text.migrations) fails with

FATAL ERROR - The following SQL query failed: ALTER TABLE "text_text_id_seq" RENAME TO "cmsplugin_text_id_seq";
The error was: relation "text_text_id_seq" does not exist

I tried patch at #1057 but this doesn't solve the issue.

Tried with both PostgreSQL 8.4 and 9.1, in different virtualenvs and different machines

Reverting to South 0.7.3 solves the issue

Change History

comment:1 Changed 2 years ago by andrew

  • Status changed from new to closed
  • Resolution set to worksforme
  • Milestone set to 1.0

I've just tried to replicate this with both an alter_column on a ForeignKey? and a rename_table and both work just fine. If things are still failing for you with the current development revision, please reopen and include a full traceback, an example models file, and the generated migration file, if possible.

comment:2 Changed 2 years ago by gas

Similar problem is happening to me with kinda same error message :

FATAL ERROR - The following SQL query failed: ALTER TABLE "items_externallink_pkey" RENAME TO "items_link_pkey";
The error was: relation "items_externallink_pkey" does not exist

The table renaming actually goes through. In my case, I'm renaming "ExternalLink?" model to "Link". This ExternalLink? model is a subclass of a concrete model, which might be one explanation for this Fatal error.

comment:3 Changed 2 years ago by andrew

As my closing message states, I need a full traceback/all console output, an example models file, and the generated migration file if I'm going to have a chance at finding this bug.

Note: See TracTickets for help on using tickets.