我想通過Django中的用戶配置文件(1.2.5,在Ubuntu natty中提供的版本)的方式向用戶添加一些額外的屬性,但每當我創建新用戶通過管理控制檯,包含一個新屬性(例如,「電話」),我得到一個「列user_id不是唯一的」IntegrityError。列user_id不是唯一的,用Django UserProfiles
我看到其他人有過這樣的問題,他們似乎加入了獨特的dispatch_uid到USERPROFILE創作信號已經解決了這個問題,但是這不是爲我工作:
from django.db import models
from django.contrib.auth.models import User
from django.db.models.signals import post_save
class UserProfile(models.Model):
user = models.OneToOneField(User)
phone = models.CharField(max_length=40,blank=True,null=True)
def create_user_profile(sender, instance, **kwargs):
UserProfile.objects.get_or_create(user=instance)
post_save.connect(create_user_profile, sender=User, dispatch_uid="users-profilecreation-signal")
AUTH_PROFILE_MODULE設爲指向這個類,在settings.py中。
任何人都知道我在做什麼錯了?
這是問題,非常感謝。 – paul88888