views:

184

answers:

2

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!

+1  A: 

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?

John Feminella
Thanks John. I'm sure it will probably work, maybe it's just not supported by **django-evolution**. I'm a little scared of deleting and re-syncing the model just in case I loose existing data in the db including ForeignKeys.I would even try migrating the model structure myself, but I don't know how to go on about it.
RadiantHex
Gotcha. This might be a good question for the django-evolution mailing list. It's at http://groups.google.com/group/django-evolution. In the meantime, I'd try cloning your database and seeing what you get when you use the model in a clean environment like I mentioned above.
John Feminella
+1  A: 

Same thing, i answer your another question http://stackoverflow.com/questions/2098696 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

diegueus9