gpt4 book ai didi

python - 关于 "User.add_to_class"扩展我的用户的错误?我不知道为什么

转载 作者:行者123 更新时间:2023-11-29 05:46:20 24 4
gpt4 key购买 nike

在我的 models.py 中,我使用这些代码来扩展两个字段:

User.add_to_class('bio', models.TextField(blank=True))
User.add_to_class('about', models.TextField(blank=True))

但是当我创建一个用户时:

user = User.objects.create_user(username=self.cleaned_data['username'], \
email=self.cleaned_data['email'],password=self.cleaned_data['password1'])

有这样的错误:

ProgrammingError at /account/register/
(1110, "Column 'about' specified twice")

Request Method: POST
Request URL: http://127.0.0.1:8000/account/register/
Exception Type: ProgrammingError
Exception Value: (1110, "Column 'about' specified twice")

我检查了 django 创建的 sql,我发现它很奇怪:

'INSERT INTO `auth_user` (`username`, `first_name`, `last_name`, `email`, `password`, `is_staff`, `is_active`, `is_superuser`, `last_login`, `date_joined`, `about`,'bio','about','bio') VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)'

about 和bio 有两个。但是在Mysql 表中只有'about' 和'bio' 一个。另一方面,在这种情况下,models.py 将运行两次,我不知道。

我不知道为什么。请帮助我!

最佳答案

这是 not a good way to store additional user information ,出于多种原因,正如 James Bennett 在链接的线程中指出的那样。您会得到奇怪的 SQL 输出并且难以调试它,这并不奇怪。改用相关的配置文件模型,让事情变得简单。

关于python - 关于 "User.add_to_class"扩展我的用户的错误?我不知道为什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1389627/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com