Can't access users in admin after migration
Asked Answered
R

2

1

So I successfully migrated from a profile model to an extended User model. The data migration all worked fine, but I can't access my users from the admin, I get the following error:

DatabaseError: (1146, "Table 'mydb.app_myuser_groups' doesn't exist")

All I have defined in models.py is the following:

class MyUser(AbstractUser):
    isSpecial = models.BooleanField(default=True)

having followed these instructions. Is there more I need to do to get this to work?

Rollick answered 30/4, 2013 at 11:0 Comment(2)
Might be a dumb question but: does app_myuser_groups exist in the mydb database ?Name
@Steve Well no, but I'm wondering why the admin thinks it should be.Rollick
H
1

See my previous answer here and modify step 4 to look like this:

# encoding: utf-8
from south.db import db
from south.v2 import SchemaMigration

class Migration(SchemaMigration):

    def forwards(self, orm):
        # Fill in the destination name with the table name of your model
        db.rename_table('auth_user', 'accounts_user')
        db.rename_table('auth_user_groups', 'accounts_user_groups')

    def backwards(self, orm):
        db.rename_table('accounts_user', 'auth_user')
        db.rename_table('accounts_user_groups', 'auth_user_groups')

    models = { ....... } # Leave this alone
Hutment answered 1/5, 2013 at 23:53 Comment(0)
N
0

AbstractUser inherits from PermissionMixin, which has a ManyToManyField to the Group model. So there should be a app_myuser_groups table in the database. South may be able to create the intermediate table, but I don't know how. What I know is that syncdbing after having removed app_myuser should work, even though your migration would be shredded.

This question about adding a through table in a migration should give you more insight.

Name answered 30/4, 2013 at 22:12 Comment(3)
Having done my migrations via rename_table, can I just use this approach with the other auth tables? I'm surprised this hasn't been covered elsewhere...Rollick
Unfortunately I'm still not at ease with South migrations. I have only one site in production (made at a time when I didn't know well about DRY and South), and my other sites are often DB-reset.Name
I have taken a look at migrate_table and I don't see why you wouldn't be able to use it for the other tables, even the intermediate ones. One other thing, maybe too dificult, would be to change the groups field and add a db_table argument, pointing to an existing intermediate table.Name

© 2022 - 2024 — McMap. All rights reserved.