Opened 6 years ago

Closed 6 years ago

#28813 closed Bug (duplicate)

Sqlite migration of manual primary key

Reported by: cecedille1 Owned by: nobody
Component: Migrations Version: 1.11
Severity: Normal Keywords: sqlite
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Sqlite migration generates an invalid INSERT INTO clause when a table has no more columns. (happens with manual primary keys)

BEGIN;
--
-- Remove field f1 from poc
--
ALTER TABLE "app_poc" RENAME TO "app_poc__old";
CREATE TABLE "app_poc" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT);
INSERT INTO "app_poc" () SELECT  FROM "app_poc__old";
DROP TABLE "app_poc__old";
--
-- Add field f2 to poc
--
ALTER TABLE "app_poc" RENAME TO "app_poc__old";
CREATE TABLE "app_poc" ("f2" integer NOT NULL PRIMARY KEY);
INSERT INTO "app_poc" ("f2") SELECT 1 FROM "app_poc__old";
DROP TABLE "app_poc__old";
COMMIT;

https://github.com/cecedille1/django-migrate-empty-columns-poc

Change History (2)

comment:1 by cecedille1, 6 years ago

One way to fix this is to create the new field first before removing the old one

comment:2 by Tim Graham, 6 years ago

Resolution: duplicate
Status: newclosed

Duplicate of #24424.

Note: See TracTickets for help on using tickets.
Back to Top