﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
9736	Primary key with space in name generates invalid constraint SQL	Russell Keith-Magee	Russell Keith-Magee	"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.
"		closed	Core (Management commands)	1.0		fixed			Accepted	0	0	0	0	0	0
