开发者

Error when adding a ManyToManyField in Django

Ok, so I posted a question recently regarding an error when adding a ManyToManyField

The Models are the ones below

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)

This is the error I get when migrating with django-evolution:

AttributeError: 'ManyToManyField' object has no attribute '_get_m2m_column_name'

So, is there a way of manually setting a ManyToManyField without specifying it within the two models? let's say with a model like this

class SpellToMagicType(models.Model):
     magic_type = models.ForeignKey(MagicType)
     spell = models.ForeignKey(Spell)

but how would I go on about using this within Django's ORM?

Help would be very much appreciated. Thanks!


Same thing, i answer your another question Is a reason I can't add a ManyToManyField? basicly this error is because your code in models (ORM) change but your database isn't, and django-evolution doesn't fix many problems with changes in the database, i suggest you look for django-extensions (http://code.google.com/p/django-command-extensions/) and the command sqldiff, but look my another answer


This is more or less the way I would have done it. In fact, I was puzzled about why this didn't work, and tried it myself in a clean Django 1.1 environment -- it works swimmingly.

Have you tried putting this model in a clean environment yourself and seeing what you get?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜