#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 , 17 years ago
| Owner: | changed from to |
|---|---|
| Status: | new → assigned |
| Triage Stage: | Unreviewed → Accepted |
comment:2 by , 17 years ago
| Resolution: | → fixed |
|---|---|
| Status: | assigned → closed |
comment:3 by , 17 years ago
Note:
See TracTickets
for help on using tickets.
(In [9543]) Fixed #9736 -- Added quoting to the SQL constraint names generated during table creation. This is to accommodate primary keys with spaces.