Search code examples
pythondjangodjango-modelsdjango-ormdjango-evolution

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!


Solution

  • 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