Is a reason I can't add a ManyToManyField?

▼魔方 西西 提交于 2020-01-04 15:33:14

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!