运行“python manage.py migrate”时Django中的ValueError命令

编程入门 行业动态 更新时间:2024-10-26 12:25:38
本文介绍了运行“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命令

本文发布于:2023-10-22 22:20:07,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1518893.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:命令   py   manage   python   ValueError

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!