Ticket #155 (closed defect: fixed)

Opened 7 years ago

Last modified 5 years ago

startmigration --initial fails if model related to a proxy model

Reported by: pmclanahan@… Owned by: andrew
Priority: major Milestone: 0.6
Component: commands Version: 0.6-pre
Keywords: proxy model Cc:


I have a proxy model for Django's built-in User model in the contrib.auth package. For my apps which relate to this model the initialization of migrations fail with the following output:

paul@frylock:~/Projects/gdfpups$ ./manage.py convert_to_south regions
Creating migrations directory at '/home/paul/Projects/gdfpups/apps/regions/migrations'...
Creating __init__.py in '/home/paul/Projects/gdfpups/apps/regions/migrations'...
 + Added model 'regions.Region'
Traceback (most recent call last):
  File "./manage.py", line 11, in <module>
  File "/usr/local/lib/python2.6/site-packages/django/core/management/__init__.py", line 362, in execute_manager
  File "/usr/local/lib/python2.6/site-packages/django/core/management/__init__.py", line 303, in execute
  File "/usr/local/lib/python2.6/site-packages/django/core/management/base.py", line 195, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/usr/local/lib/python2.6/site-packages/django/core/management/base.py", line 222, in execute
    output = self.handle(*args, **options)
  File "/usr/local/lib/python2.6/dist-packages/south/management/commands/convert_to_south.py", line 43, in handle
    management.call_command("startmigration", app, initial=True)
  File "/usr/local/lib/python2.6/site-packages/django/core/management/__init__.py", line 166, in call_command
    return klass.execute(*args, **defaults)
  File "/usr/local/lib/python2.6/site-packages/django/core/management/base.py", line 222, in execute
    output = self.handle(*args, **options)
  File "/usr/local/lib/python2.6/dist-packages/south/management/commands/startmigration.py", line 561, in handle
    all_models[key] = prep_for_stub(model, last_models)
  File "/usr/local/lib/python2.6/dist-packages/south/management/commands/startmigration.py", line 638, in prep_for_stub
    pk: ormise_triple(model._meta.pk, remove_useless_attributes(fields[pk])),
KeyError: 'id'

I've done a little debugging and it appears that the value for "model" being passed around is an instance of ModelBase?, which has no pk. The above is from a run with the svn trunk version, but it fails similarly with 0.5.

The only model in this app is below. The GDFUser model is the proxy.

class Region(models.Model):
    title = models.CharField(max_length=100)
    slug = models.SlugField(unique=True,
        help_text="A unique string that will appear in the URL for this region.")
    field_rep = models.ForeignKey(GDFUser,
        limit_choices_to={'groups__name__iexact':'Field Representative'})
    details = models.TextField(help_text=markdown_help_text)

    class Meta:
        ordering = ('title',)

    def __unicode__(self):
        return self.title

    def get_absolute_url(self):
        return ('region_home', (), { 'region': self.slug })


Change History

comment:1 Changed 7 years ago by andrew

  • Status changed from new to assigned
  • Milestone set to 0.6

Could I have a look at the source of this 'proxy model'?

comment:2 Changed 6 years ago by pmclanahan@…

Sure. It's definitely nothing special. Just a proxy for the built-in django.contrib.auth.models.User model. I haven't done much with it yet, but I expect to need to add some stuff to it, which is why it would be nice to use. It has been causing some headaches however.

class GDFUser(User):
    """Proxy class for User"""
    class Meta:
        proxy = True
    def __unicode__(self):
        return self.get_full_name() or self.username

comment:3 Changed 6 years ago by andrew

No problem; proxy models are one of those new 1.1 features I should really get around to fixing! I'll get onto it soon, once exams are over.

comment:4 Changed 6 years ago by pmclanahan@…

Yeah. It's what I get for following trunk :)

I'll do my best to figure it out and send you a patch. It'd be the
least I could do. If I can get this working it'll save me a TON of
time when I deploy the next version of a site I'm working on.


comment:5 Changed 6 years ago by andrew

  • Status changed from assigned to closed
  • Resolution set to fixed

Fixed in [b881df2d7e4e].

Note: See TracTickets for help on using tickets.