Opened 19 years ago

Closed 19 years ago

Last modified 18 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

Description

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 by Manuzhai, 19 years ago

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 by Adrian Holovaty, 19 years ago

Resolution: fixed
Status: newclosed

Fixed in [227].

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