问题
So I'm building a Django application, and these are a few models I have:
class MagicType(models.Model):
name = models.CharField(max_length=155)
parent = models.ForeignKey('self', null=True, blank=True)
class Spell(models.Model):
name = models.CharField(max_length=250, db_index=True)
magic_words = models.CharField(max_length=250, db_index=True)
magic_types = models.ManyToManyField(MagicType)
When syncing the models I'm getting this error:
AttributeError: 'ManyToManyField' object has no attribute '_get_m2m_column_name'
Is there a reason this is happening? How can I fix this?
Help would be very much appreciated.
EDIT:
I'm using django-evolution http://code.google.com/p/django-evolution/
回答1:
I suggest you use django-extensions , this will give you a commnad sqldiiff
that works better than evolution, because there is a problem creating the intermediate table between MagicType and MagicType.
I suggest you run the command sqlall yourapp
and execute directly the sql code of the creation of the new intermediate table. Evolution doesn't it for you :(
回答2:
Is MagicType declared in the same models file (and before) Spell?
Does magic_types = models.ManyToManyField('MagicType')
work (with 'MagicType' quoted)?
来源:https://stackoverflow.com/questions/2098696/is-a-reason-i-cant-add-a-manytomanyfield