【问题标题】:Can't access users in admin after migration迁移后无法访问管理员中的用户
【发布时间】:2013-04-24 06:36:51
【问题描述】:

所以我成功地从配置文件模型迁移到扩展用户模型。数据迁移一切正常,但我无法从管理员访问我的用户,我收到以下错误:

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

我在models.py 中定义的内容如下:

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

已关注these instructions。我还需要做更多的事情才能让它发挥作用吗?

【问题讨论】:

  • 可能是一个愚蠢的问题,但是:app_myuser_groups 是否存在于 mydb 数据库中?
  • @Steve 不,但我想知道为什么管理员认为它应该是。

标签: django django-admin django-1.5


【解决方案1】:

查看我之前的回答 here 并修改第 4 步,如下所示:

# 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 继承自 PermissionMixin,它有一个 ManyToManyField 到 Group 模型。所以数据库中应该有一个app_myuser_groups 表。 South 可能能够创建中间表,但我不知道如何。我所知道的是,在删除 app_myuser 之后 syncdbing 应该可以工作,即使您的迁移会被粉碎。

    这个关于adding a through table in a migration 的问题应该会给你更多的洞察力。

    【讨论】:

    • 通过rename_table 完成了我的迁移,我可以将这种方法与其他auth 表一起使用吗?我很惊讶这在其他地方没有被报道......
    • 不幸的是,我仍然对南方迁移感到不安。我只有一个网站在生产中(当时我不太了解 DRY 和 South),而我的其他网站经常是 DB-reset。
    • 我查看了migrate_table,我不明白为什么您不能将它用于其他表,甚至是中间表。另一件事可能太难了,就是更改groups 字段并添加一个db_table 参数,指向现有的中间表。
    猜你喜欢
    • 2013-03-11
    • 2014-05-17
    • 1970-01-01
    • 2017-06-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-02
    • 1970-01-01
    相关资源
    最近更新 更多