Ticket #424 (closed defect: duplicate)

Opened 5 years ago

Last modified 5 years ago

Custom ForeignKey Field does not get _id postfix on sqlite

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

Description

I've only tested this on sqlite

I've got a custom field that subclasses the standard Django ForeignKey field (it hardcodes the related model).

After generating and running a migration for a model using this field the following exception gets thrown:

django.db.utils.DatabaseError: table contentpages_contentpage has no column named image_id

--verbosity=2 shows the following SQL (image is the field using the 'special' FK field)

CREATE TABLE "_south_new_contentpages_contentpage"
("body" text, "created" datetime, "image" integer NOT NULL DEFAULT '',
"title" varchar(100), "modified" datetime, "node_id" integer UNIQUE,
"id" integer PRIMARY KEY)

INSERT INTO "_south_new_contentpages_contentpage" SELECT
"body", "created", "image", "title", "modified", "node_id", "id"
FROM "contentpages_contentpage";

DROP TABLE "contentpages_contentpage";

ALTER TABLE "_south_new_contentpages_contentpage"
RENAME TO "contentpages_contentpage";

CREATE TABLE "_south_new_contentpages_contentpage"
("body" text, "title" varchar(100), "image" integer, "created" datetime,
"modified" datetime, "node_id" integer NOT NULL UNIQUE,
"id" integer PRIMARY KEY)

INSERT INTO "_south_new_contentpages_contentpage"
SELECT "body", "title", "image", "created", "modified", "node_id", "id"
FROM "contentpages_contentpage";

DROP TABLE "contentpages_contentpage";

ALTER TABLE "_south_new_contentpages_contentpage"
RENAME TO "contentpages_contentpage";

CREATE INDEX "contentpages_contentpage_image_id"
ON "contentpages_contentpage" ("image_id");

As you can see, the image field never gets the expected _id postfix.

Attachments

sqlite3_add_column.patch (703 bytes) - added by jaap@… 5 years ago.

Change History

comment:1 Changed 5 years ago by anonymous

I've tried this with a normal ForeignKey? field and it doesn't work either. I'm not sure what's going on as I'm near certain that this used to work.

Changed 5 years ago by jaap@…

comment:2 Changed 5 years ago by jaap@…

I've added a patch (hopefully in the right format, it's the output of hg diff).

Migration adding a ForeignKey? on sqlite seem to work fine with this patch applied.

comment:3 Changed 5 years ago by anonymous

This all seems to be caused by the fix for ticket:402

I didn't realize I was working with a trunk version of South instead of 0.7 before.

comment:4 Changed 5 years ago by andrew

  • Status changed from new to assigned
  • Version changed from 0.7 to tip
  • Milestone set to 0.7.1

comment:5 Changed 5 years ago by andrew

  • Status changed from assigned to closed
  • Resolution set to duplicate

This looks to be a duplicate of #415, on second analysis.

Note: See TracTickets for help on using tickets.