Opened 10 years ago

Closed 10 years ago

Last modified 9 years ago

#84 closed defect (fixed)

Foreign keys don't work in MySQL

Reported by: Manuzhai Owned by: adrian
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: UI/UX:

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 Changed 10 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 10 years ago by adrian

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

Fixed in [227].

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