#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).
Note:
See TracTickets
for help on using tickets.
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.