【发布时间】:2009-09-07 14:17:05
【问题描述】:
在我的 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 将运行两次,我不知道。
我不知道为什么。请帮助我!
【问题讨论】:
-
models.py是否被执行了两次?你能保护User.add_to_class代码吗?