Opened 11 years ago

Closed 11 years ago

#5729 closed (fixed)

Django doesn't create real foreign keys when using MySQL INNODB engine

Reported by: mattdennewitz Owned by: Malcolm Tredinnick
Component: Database layer (models, ORM) Version: master
Severity: Keywords:
Cc: mir@… Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


When specifying in DATABASE_OPTIONS to use MySQL's INNODB engine, Django will oblige and create the tables using MySQL. It won't, however, create real foreign keys; instead, it adds indexes as though it were using MyISAM.

Change History (4)

comment:1 Changed 11 years ago by Malcolm Tredinnick

Owner: changed from nobody to Malcolm Tredinnick
Triage Stage: UnreviewedAccepted

Yep. I noticed this recently when switching to MySQL for a project. I've got a fix for this that I've been debugging in my local tree. I'll commit it shortly.

One day the MySQL devs will really have to implement the correct syntax handling. :-(

comment:2 Changed 11 years ago by Michael Radziej

Cc: mir@… added

comment:3 Changed 11 years ago by mattdennewitz


comment:4 Changed 11 years ago by Malcolm Tredinnick

Resolution: fixed
Status: newclosed

(In [6650]) Fixed #5729 -- For MySQL (only), always delay the creation of foreign key
references, for all tables, until after the table has been created. This means
that when using the InnoDB storage engine, true foreign key constraints are
created (inline "REFERENCES" are ignored by InnoDB, unfortunately).

Fully backwards compatible.

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