Ticket #1070 (assigned defect)

Opened 2 years ago

Last modified 2 years ago

migration fails with m2m field, with certain attributes defined, pointing proxy model

Reported by: waterbotte@… Owned by: andrew
Priority: major Milestone: 1.0
Component: commands Version: 0.7.4
Keywords: Cc:


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.

In the same model, Item, there's another ManyToManyField? pointing to the said proxy model, ExtendedUser?.

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).

Change History

comment:1 Changed 2 years ago by andrew

  • Status changed from new to assigned
  • Version changed from 0.7.3 to 0.7.4
  • Milestone set to 1.0

Hmm, I thought this was already fixed in #496, but apparently not. I'll take a look when I get the chance.

Note: See TracTickets for help on using tickets.