Django

Code

Ticket #9736 (closed: fixed)

Opened 7 months ago

Last modified 7 months ago

Primary key with space in name generates invalid constraint SQL

Reported by: russellm Assigned to: russellm
Milestone: Component: django-admin.py
Version: 1.0 Keywords:
Cc: Triage Stage: Accepted
Has patch: 0 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

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.

Attachments

Change History

12/02/08 05:54:18 changed by russellm

  • status changed from new to assigned.
  • needs_better_patch changed.
  • needs_tests changed.
  • owner changed from nobody to russellm.
  • needs_docs changed.
  • stage changed from Unreviewed to Accepted.

12/02/08 07:23:29 changed by russellm

  • status changed from assigned to closed.
  • resolution set to fixed.

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

12/02/08 07:34:01 changed by russellm

(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.


Add/Change #9736 (Primary key with space in name generates invalid constraint SQL)




Change Properties
Action