运行“python manage.py migrate”时Django中的ValueError命令 [英] ValueError in Django when running the "python manage.py migrate" command

查看:2652
本文介绍了运行“python manage.py migrate”时Django中的ValueError命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要向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命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆