爲了實現簡單的目標,我遵循Django文檔here:創建新用戶後立即創建用戶配置文件。Django - 在創建用戶時創建用戶配置文件
我有一個「賬戶」,應用程序和我accounts.models看起來是這樣的:
# -*- coding: utf-8 -*-
from django.db import models
from django.db.models.signals import post_save
from django.contrib.auth.models import User
from main.models import Store
class UserProfile(models.Model):
GENRE_CHOICES = (
('m', 'Masculino'),
('f', 'Feminino'),
)
MARITAL_STATUS_CHOICES = (
('s', 'Solteiro'),
('c', 'Casado'),
('d', 'Divorciado'),
('v', 'Viúvo'),
)
user = models.ForeignKey(User, unique=True)
birth_date = models.DateField()
genre = models.CharField(max_length=1, choices=GENRE_CHOICES)
address = models.CharField(max_length=150)
postal_code_4 = models.PositiveIntegerField()
postal_code_3 = models.PositiveIntegerField()
locatity = models.CharField(max_length=30)
marital_status = models.CharField(max_length=1, choices=MARITAL_STATUS_CHOICES)
child_amount = models.PositiveSmallIntegerField()
is_merchant = models.BooleanField(default=False)
store = models.ForeignKey(Store, null=True)
def create_user_profile(sender, instance, created, **kwargs):
if created:
UserProfile.objects.create(user=instance)
post_save.connect(create_user_profile, sender=User)
一切看起來沒什麼問題,但嘗試添加新用戶時(使用Django管理),而不是有新創建的用戶和用戶配置文件,我得到以下錯誤: InternalError該在/管理/認證/用戶/添加/ 當前事務被中止,忽略,直到事務塊
這裏結束命令是追蹤誤差部分:
/djangoProjects/lwboanova/lwboanova/apps/accounts/models.py in create_user_profile
34: UserProfile.objects.create(user=instance)
這似乎是一個完整性錯誤,但我沒有得到它的原因。
如果有任何雅可以給我一些幫助,這將是偉大的。
您是否安裝了django工具欄?如果是這樣,請嘗試禁用它,以便獲得更好的錯誤信息。 – 2012-07-15 02:50:37