views:

660

answers:

2

Hi all,

I am getting this error when running "./manage.py migrate app_name"

While loading migration 'whatever.0001_initial':
Traceback (most recent call last):
 File "manage.py", line 14, in <module> execute_manager(settings)

...tons of other stuff..

   raise KeyError("The model '%s' from the app '%s' is not available in this migration." % (model, app))
KeyError: "The model 'appuser' from the app 'whatever' is not available in this migration."

I am sure that model "appuser" is both in application models.py and in 0001_initial.py

AppUser model from models.py:

class AppUser(models.Model):
    person = models.OneToOneField('Person')
    user = models.ForeignKey(User, unique=True)
    class Meta:
        permissions = (
            ('is_one', 'one'),
            ('is_two', 'two')
        )
    def __unicode__(self):
        return self.person.__unicode__()

AppUser model from 0001_initial.py:

    # Adding model 'AppUser'
    db.create_table('app_appuser', (
        ('person', models.OneToOneField(orm.Person)),
        ('id', models.AutoField(primary_key=True)),
        ('user', models.ForeignKey(orm['auth.User'], unique=True)),
    ))
    db.send_create_signal('app', ['AppUser'])
    ...
    'app.appuser': {
        'Meta': {'permissions': "(('is_one','one'),('is_two','two'))"},
        'id': ('models.AutoField', [], {'primary_key': 'True'}),
        'person': ('models.OneToOneField', ["'Person'"], {}),
        'user': ('models.ForeignKey', ['User'], {'unique': 'True'})
    },

I am trying to run it on empty database (ie. no "app_*" tables) like that:

manage.py migrate app

This seem to be happening only on python 2.5 on Mac OS, no probs with Ubuntu/python 2.6

Question - how to fix?

Thanks!

+1  A: 

What's the migration you're trying to run? Can we see the 0001_initial file itself?

It's rather big, it contains all the models for the app
Art
I'll post AppUser though
Art
+1  A: 

The problem seemed to be with the order of models in the 0001_initial.py file. There was a class which derived from AppUser. When I re-created the migration on Mac OS with

manage.py startmigration app --initial

and compared that to one generated on Ubuntu the order of models was different. So when I changed the order to match the one on Mac OS, everything worked fine.

This problem seems to exist only in 0.5 version of south and is supposedly fixed on trunk.

Art