Opened 13 years ago

Closed 13 years ago

Last modified 12 years ago

#84 closed defect (fixed)

Foreign keys don't work in MySQL

Reported by: Manuzhai Owned by: Adrian Holovaty
Component: Database layer (models, ORM) Version:
Severity: major Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


Django generates: post_id mediumint(9) unsigned auto_increment NOT NULL REFERENCES posts_posts (slug)

This doesn't work. In MySQL, only one column can have auto_increment, and that same column has to be the PRIMARY KEY. I think there should be a separate DATATYPE for ForeignKeys (it seems to just reuse the AutoField).

Change History (2)

comment:1 Changed 13 years ago by Manuzhai

Hmm, this is actually harder than I thought. You obviously want to reuse the definition for the foreign field since it may not be an AutoField (by defining primary_key = True on some other field). The easiest solution then seems to just strip the 'auto_increment' part from the definition. That's kind of ugly, though.

comment:2 Changed 13 years ago by Adrian Holovaty

Resolution: fixed
Status: newclosed

Fixed in [227].

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