Can't access users in admin after migration

2019-08-13 22:08发布

问题:

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?

回答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


回答2:

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.