我需要向 Django 的 User 模型添加更多字段,因此我在名为 accounts 的应用程序中创建了一个自定义模型类(名为 Accounts) ) 扩展了 Django 的 AbstractUser 类。
之后,我更新了 settings.py 文件,定义了 AUTH_USER_MODEL 属性:
AUTH_USER_MODEL = 'accounts.Accounts'
然后,我使用 python manage.py makemigrations
命令为自定义模型创建了一个迁移文件。
之后,我运行了 python manage.py migrate
命令,并收到了以下错误消息:
ValueError: The field admin.LogEntry.user was declared with a lazy reference to 'accounts.accounts', but app 'accounts' isn't installed.
错误的原因是什么以及如何修复它?
更新:
现在,如果我运行 python manage.py makemigrations
命令,我会收到以下错误消息:
ValueError: The field admin.LogEntry.user was declared with a lazy reference to 'accounts.accounts', but app 'accounts' doesn't provide model 'accounts'.
最佳答案
您只需删除迁移文件夹中以前的 0001_initial.py 并尝试再次进行 makemigration 和迁移
关于django - 运行 "python manage.py migrate"命令时 Django 中出现 ValueError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40222268/