app.model: 'fieldname' is a manually-defined m2m relation through model Zzzzz, which does not have foreign keys to XXX and YYY
django1.5 でmanytomany field で中間テーブルを使うときに出たエラー
class Group(models.Model): name = models.CharField(max_length=40) user = models.ManyToManyField(User, through='Staff') def __unicode__(self): return self.name class Staff(models.Model): name = models.ForeignKey(User, related_name='staffname') def __unicode__(self): return self.name
これでsyncdbしたら、次のようなエラーが
app.groups: 'user' is a manually-defined m2m relation through model Staff, which does not have foreign keys to User and Group
とのことなので、Staff のモデルにはUserの外部キーは持っているが、groupの外部キーがなかったので追加する。
class Staff(models.Model): name = models.ForeignKey(User, related_name='staffname') group = models.ForeignKey(Group, related_name='staffname') def __unicode__(self): return self.name