Can't access users in admin after migration

给你一囗甜甜゛ 提交于 2020-01-05 18:42:23

问题


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.



来源:https://stackoverflow.com/questions/16298236/cant-access-users-in-admin-after-migration

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!