Opened 9 years ago

Closed 9 years ago

#5729 closed (fixed)

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

Reported by: mattdennewitz Owned by: mtredinnick
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: UI/UX:


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 9 years ago by mtredinnick

  • Needs documentation unset
  • Needs tests unset
  • Owner changed from nobody to mtredinnick
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

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 9 years ago by mir

  • Cc mir@… added

comment:3 Changed 9 years ago by mattdennewitz


comment:4 Changed 9 years ago by mtredinnick

  • Resolution set to fixed
  • Status changed from new to closed

(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