我需要向Django的用户模型添加更多字段,因此我在名为帐户的应用程序中创建了一个自定义模型类(名为帐户 )扩展Django的 AbstractUser 类。
I needed to add more fields to Django's User model, so I created a custom model class (named Accounts in an app named accounts) that extends Django's AbstractUser class.
之后,我更新了我的 settings.py 文件, strong> AUTH_USER_MODEL属性:
After that, I updated my settings.py file, defining the AUTH_USER_MODEL property:
AUTH_USER_MODEL = 'accounts.Accounts'然后,我使用 python manage.py makemigrations 命令为自定义模型创建了一个迁移文件
I then created a migration file for the custom model using the python manage.py makemigrations command.
之后,我运行了 python manage.py migrate 命令,并收到以下错误消息: p>
After that, I ran the python manage.py migrate command and I got this error message:
ValueError: The field admin.LogEntry.user was declared with a lazy reference to 'accounts.accounts', but app 'accounts' isn't installed.错误的原因是什么,如何解决?
What's the cause of the error and how can I fix it?
更新:现在,如果我运行 python manage.py makemigrations 命令,我会收到以下错误消息:
UPDATE: Now, if i run the python manage.py makemigrations command, I get this error message:
ValueError: The field admin.LogEntry.user was declared with a lazy reference to 'accounts.accounts', but app 'accounts' doesn't provide model 'accounts'.推荐答案
您没有添加帐户到您的INSTALLED_APPS。从评论中,我可以在您的应用列表中看到 accounts.apps.AccountsConfig 。而不是添加帐户到您的INSTALLED_APPS
You didn't add accounts to your INSTALLED_APPS. From the comment, I can see accounts.apps.AccountsConfig in your list of apps. Instead of it, just add accounts to your INSTALLED_APPS
更多推荐
运行“python manage.py migrate”时Django中的ValueError命令
发布评论