0

User.profile から更新フォームを作成しようとしています。しかし、URLをロードするとエラーが発生します:

IntegrityError at /accounts/profile/
userprofile_userprofile.dob may not be NULL

「dob」を として指定しnull=Trueても、同じエラーが発生します。しかし、管理者から UserProfiles を追加できます。私はどこで間違っていますか?助けてください。

models.py:

from django.db import models
from django.contrib.auth.models import User
from time import time


def get_upload_file_name(instance, filename):
    return "uploaded_files/profile/%s_%s" %(str(time()).replace('.','_'), filename)

class UserProfile(models.Model):

    GENDER = (
        ("M", "Male"),
        ("F", "Female"),
        ("O", "Other"),
        )

    RELATIONSHIP = (
        ("S", "Single"),
        ("M", "Married"),
        ("D", "Divorced"),
        )

    user = models.OneToOneField(User)
    image = models.ImageField(upload_to=get_upload_file_name)
    gender = models.CharField(max_length=1, choices=GENDER) 
    dob = models.DateField('date of birth', blank=True, null=True)
    about = models.TextField()
    occupation = models.CharField(max_length=30)
    state = models.CharField(max_length=20)
    t_address = models.CharField(max_length=30)
    p_address = models.CharField(max_length=30)
    relationship = models.CharField(max_length=1, choices=RELATIONSHIP)

User.profile = property(lambda u: UserProfile.objects.get_or_create(user=u)[0])

フォーム.py:

from django import forms
from models import UserProfile

class UserProfileForm(forms.ModelForm):

    class Meta:
        model = UserProfile
        fields = ('image', 'gender', 'dob', 'about', 'state', 't_address', 'p_address', 'relationship')
4

2 に答える 2

2

編集を行う前に既に syncdb を実行している可能性があります (karthikr のコメントを参照してください)。テーブルを削除して syncdb を再実行するか、SQL を使用してテーブルを編集できます。

ALTER TABLE user_profile ALTER COLUMN dob DROP NOT NULL;
于 2013-08-18T19:05:40.200 に答える