Ticket #1070 (assigned defect)
migration fails with m2m field, with certain attributes defined, pointing proxy model
|Reported by:||waterbotte@…||Owned by:||andrew|
This one is similar to ticket #496, if not of the same problem.
I am actually using South v0.7.4 (not available from the pull-down).
It appears that there is a problem migrating applications that have a model with a ManyToManyField? pointing to a proxy model (in my case, it's a proxy model for django's User model).
Below is the code for my case:
class ExtendedUser(User): class Meta: proxy = True class Item(Model): ... watchers = models.ManyToManyField(ExtendedUser, related_name='watching_items') ...
I created initial migration with the above model definitions. As soon as I tried to migrate it, I got the following error:
KeyError: "The model 'extendeduser' from the app 'lend_borrow' is not available in this migration."
So I inspected the migration and found the following trouble:
db.create_table('lend_borrow_item_watchers', ( ('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True)), ('item', models.ForeignKey(orm['lend_borrow.item'], null=False)), ('extendeduser', models.ForeignKey(orm['lend_borrow.extendeduser'], null=False)) )) db.create_unique('lend_borrow_item_watchers', ['item_id', 'extendeduser_id'])
The prolem is the lend_borrow.extendeduser in the above code, which should have been auth.user. Also, for the sake of completeness, the names auto-generated based on the name of the proxy model, ExtendedUser?, should also have been based on the actual underlying model, User, instead.
class Item(Model): ... requesters = models.ManyToManyField(ExtendedUser, through='ItemRequest') ...
But what's interesting here is that the migration has correct entries for this ManyToManyField? and thus no issue. From the look of it, this issue occurs only on ManyToManyField? with certain conditions met (in my case, it has related_name and no through).