Reputation: 6612
I can't get Django (1.5) to create MySQL UNIQUE
indexes on 3 columns, even though I've followed every suggestion I found on SO. Here's how my model looks like:
class Loc(models.Model):
rand = models.IntegerField()
sectiune = models.ForeignKey(Sectiune)
numar = models.IntegerField()
pret = models.FloatField()
def __unicode__(self):
return str(self.sectiune.nume) + ': R' + str(self.rand) + ' L' + str(self.numar)
class Meta:
unique_together = (("rand","sectiune","numar"),)
I really don't get what's wrong. I've seen a bug report that unique_together
doesn't work on foreign keys, but I've also seen that has been fixed. Any help?
Upvotes: 0
Views: 2311
Reputation: 6612
Turns out Django is not that smart after all... It doesn't know how to ALTER
a table to create the UNIQUE
constraint. I just had to delete the tables, run syncdb
again, and the constraints were there :)
Upvotes: 2