列user_id并非唯一,对于Django UserProfiles [英] column user_id is not unique, with Django UserProfiles

查看:75
本文介绍了列user_id并非唯一,对于Django UserProfiles的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过Django中的用户个人资料(1.2.5,Ubuntu natty中提供的版本)向用户添加一些额外的属性,但是每当我通过管理控制台创建一个新用户时,在包括的新属性(例如电话)中,我得到了列user_id不是唯一的 IntegrityError。

I'm trying to add some extra attributes to a user by way of a User Profile in Django (1.2.5, the version supplied in Ubuntu natty), but whenever I create a new user through the admin console, with one of the new attributes included (eg, 'phone'), I get a "column user_id is not unique" IntegrityError.

我看到其他人也遇到了这个问题,并且他们似乎已通过在用户个人资料创建信号中添加唯一的dispatch_uid解决了这一问题,但这对我不起作用:

I see that other people have had this problem, and they seem to have solved it by adding a unique dispatch_uid to the userprofile creation signal, but that's not working for me:

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中。

AUTH_PROFILE_MODULE is set to point at this class, in settings.py.

有人知道我在做什么吗?

Anyone know what I'm doing wrong?

推荐答案

有两次尝试创建相同的配置文件。

There are two attempts to create the same profile. One from the signal and one directly from the inlined admin form.

此信号问题/答案详细介绍了该问题和可能的解决方案。

This question/answer covers it and a potential solution in more detail.

这篇关于列user_id并非唯一,对于Django UserProfiles的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆