#34881: Model-rename migration fails with IntegrityError if m2m relations to
self
exist
-------------------------------+--------------------------------------
Reporter: dennisvang | Owner: nobody
Type: Bug | Status: new
Component: Uncategorized | Version: 4.2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Comment (by Natalia Bidart):
Following the ticket description, I have been able to reproduce.
Migrations are attached, and SQLs are:
* 0001
{{{#!sql
BEGIN;
--
-- Create model Person
--
CREATE TABLE "ticket_34881_person" ("id" integer NOT NULL PRIMARY KEY
AUTOINCREMENT, "name" varchar(255) NOT NULL);
--
-- Create model Relation
--
CREATE TABLE "ticket_34881_relation" ("id" integer NOT NULL PRIMARY KEY
AUTOINCREMENT, "child_id" bigint NOT NULL REFERENCES "ticket_34881_person"
("id") DEFERRABLE INITIALLY DEFERRED, "parent_id" bigint NOT NULL
REFERENCES "ticket_34881_person" ("id") DEFERRABLE INITIALLY DEFERRED);
--
-- Add field parents_or_children to person
--
CREATE TABLE "new__ticket_34881_person" ("id" integer NOT NULL PRIMARY KEY
AUTOINCREMENT, "name" varchar(255) NOT NULL);
INSERT INTO "new__ticket_34881_person" ("id", "name") SELECT "id", "name"
FROM "ticket_34881_person";
DROP TABLE "ticket_34881_person";
ALTER TABLE "new__ticket_34881_person" RENAME TO "ticket_34881_person";
CREATE INDEX "ticket_34881_relation_child_id_77021f7a" ON
"ticket_34881_relation" ("child_id");
CREATE INDEX "ticket_34881_relation_parent_id_20447c41" ON
"ticket_34881_relation" ("parent_id");
COMMIT;
}}}
* 0002 (I renamed `Person` to `PersonFoo`)
{{{#!sql
BEGIN;
--
-- Rename model Person to PersonFoo
--
ALTER TABLE "ticket_34881_person" RENAME TO "ticket_34881_personfoo";
CREATE TABLE "new__ticket_34881_relation" ("id" integer NOT NULL PRIMARY
KEY AUTOINCREMENT, "child_id" bigint NOT NULL REFERENCES
"ticket_34881_personfoo" ("id") DEFERRABLE INITIALLY DEFERRED, "parent_id"
bigint NOT NULL REFERENCES "ticket_34881_person" ("id") DEFERRABLE
INITIALLY DEFERRED);
INSERT INTO "new__ticket_34881_relation" ("id", "parent_id", "child_id")
SELECT "id", "parent_id", "child_id" FROM "ticket_34881_relation";
DROP TABLE "ticket_34881_relation";
ALTER TABLE "new__ticket_34881_relation" RENAME TO
"ticket_34881_relation";
CREATE INDEX "ticket_34881_relation_child_id_77021f7a" ON
"ticket_34881_relation" ("child_id");
CREATE INDEX "ticket_34881_relation_parent_id_20447c41" ON
"ticket_34881_relation" ("parent_id");
CREATE TABLE "new__ticket_34881_relation" ("id" integer NOT NULL PRIMARY
KEY AUTOINCREMENT, "parent_id" bigint NOT NULL REFERENCES
"ticket_34881_personfoo" ("id") DEFERRABLE INITIALLY DEFERRED, "child_id"
bigint NOT NULL REFERENCES "ticket_34881_person" ("id") DEFERRABLE
INITIALLY DEFERRED);
INSERT INTO "new__ticket_34881_relation" ("id", "child_id", "parent_id")
SELECT "id", "child_id", "parent_id" FROM "ticket_34881_relation";
DROP TABLE "ticket_34881_relation";
ALTER TABLE "new__ticket_34881_relation" RENAME TO
"ticket_34881_relation";
CREATE INDEX "ticket_34881_relation_parent_id_20447c41" ON
"ticket_34881_relation" ("parent_id");
CREATE INDEX "ticket_34881_relation_child_id_77021f7a" ON
"ticket_34881_relation" ("child_id");
COMMIT;
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/34881#comment:9>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/0107018add9024e0-fe7d701e-f595-4449-8366-8c3950a5b0d9-000000%40eu-central-1.amazonses.com.