#12421: Foreign Key on Non-Primary Field fails due to lack of Index on Related
Field w/ MySQL
------------------------------------------+---------------------------------
Reporter: anonymous | Owner: nobody
Status: new | Milestone:
Component: Database layer (models, ORM) | Version: SVN
Keywords: | Stage: Unreviewed
Has_patch: 0 |
------------------------------------------+---------------------------------
SVN Revision 11924
{{{
#!python
class Relation(models.Model):
code = models.CharField(max_length=2, db_index=True)
class Meta:
db_table = u'relation_codes'
}}}
{{{
#!python
class Source(models.Model):
code = models.ForeignKey('Relation', to_field='code')
class Meta:
db_table = u'source_codes'
}}}
When trying to create the database, I get a
"_mysql_exceptions.OperationalError (#150)" on a query with the form
"ALTER TABLE ... ADD CONSTRAINT ... FOREIGN KEY ... REFERENCES" for my
foreign key relationship, checking the obvious problems I find that my
table to which I'm trying to make a relationship with has no index on the
field I wish to make a foreign key relationship with. Adding an index
allows for the problem query to be executed successfully. I am assuming an
order problem with the indices for non-primary (or non-integer) fields
being created after foreign keys are added leading to the problem.
--
Ticket URL: <http://code.djangoproject.com/ticket/12421>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en.