Opened 16 years ago

Closed 16 years ago

Last modified 16 years ago

#9736 closed (fixed)

Primary key with space in name generates invalid constraint SQL

Reported by: Russell Keith-Magee Owned by: Russell Keith-Magee
Component: Core (Management commands) Version: 1.0
Severity: Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

The following models:

class Clue(models.Model):
   clue_id = models.AutoField(primary_key=True)
   entryRef = models.ForeignKey('Entry', db_column = 'Entry Ref')
   clue = models.CharField(max_length=150)

class Entry(models.Model):
   entry_id = models.AutoField(primary_key=True, db_column='Entry ID')
   entry = models.CharField(unique=True, max_length=50)

can't be created using syncdb. This is due to the SQL generated for the deferred foreign key constraint. The following is the SQL generated for Postgres:

ALTER TABLE "app2_clue" ADD CONSTRAINT Entry Ref_refs_Entry ID_692e28e3 FOREIGN KEY ("Entry Ref") REFERENCES "app2_entry" ("Entry ID") DEFERRABLE INITIALLY DEFERRED;

Analogous code is generated for MySQL The problem is the name of the reference: Entry Ref_refs_Entry ID_692e28e3. While all other uses of column names are quoted, the constraint name (which is derived from the column names) is not quoted. As a result, the constraint name is invalid.

Change History (3)

comment:1 by Russell Keith-Magee, 16 years ago

Owner: changed from nobody to Russell Keith-Magee
Status: newassigned
Triage Stage: UnreviewedAccepted

comment:2 by Russell Keith-Magee, 16 years ago

Resolution: fixed
Status: assignedclosed

(In [9543]) Fixed #9736 -- Added quoting to the SQL constraint names generated during table creation. This is to accommodate primary keys with spaces.

comment:3 by Russell Keith-Magee, 16 years ago

(In [9545]) [1.0.X] Fixed #9736 -- Added quoting to the SQL constraint names generated during table creation. This is to accommodate primary keys with spaces.

Merge of [9543] from trunk.

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