2009-09-07 2 views
1

, 나는 사용자가이 코드 범위 내에서 두 개의 필드 :내 사용자를 확장하는 "User.add_to_class"에 대한 오류 나도 몰라 왜 내 models.py에서

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

하지만 사용자를 creat에 때 : 이 같은 오류가

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") 

내가지지합니다을 장고 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)' 

약 두 가지가 있습니다.하지만 Mysql 테이블에는 '약'과 '바이오'가 하나뿐입니다. 한편, models.py가 두 번 실행되는 경우, 나는 전혀 모른다.

나는 이유를 모르겠다. 제발 도와주세요!

+1

'models.py'가 두 번 실행되고 있습니까? 'User.add_to_class' 코드를 보호 할 수 있습니까? –

답변

2

제임스 베넷 (James Bennett)이 링크 된 스레드에서 지적한 것처럼 여러 가지 이유로 이것은 not a good way to store additional user information입니다. 이상한 SQL 출력을 얻고 디버깅하는 데 어려움을 겪는 것은 놀라운 일이 아닙니다. 대신 관련 프로필 모델을 사용하여 일을 쉽게 유지하십시오.

+0

흥미 롭습니다. googlegroup에 대한 링크를 제공해 주셔서 감사합니다. 사용자로부터 상속 받고 싶을 때 일부 비 호환성이 있으므로 잘 작동하는 프로필 메서드를 사용하지 않았습니다. – Kee

관련 문제