我假设这是因为我的超级用户依赖于尚无现有数据的 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) # required
location = models.CharField(max_length=100)
age = models.PositiveIntegerField(blank=True,null=True)
contribution_points = models.PositiveIntegerField()
#acheivements = models.ManyToMany()
def create_user_profile(sender,instance,created,**kwargs):
if created:
UserProfile.objects.create(user=instance)
post_save.connect(create_user_profile, sender=User)
但是,我最终遇到以下错误:
django.db.utils.DatabaseError: (1146, "Table 'savory_db.login_userprofile' doesn't exist")
尽管刚刚跑syncdb
我的模型是否有任何会导致此错误的矛盾字段。UserProfile 不应该应用于超级用户吗?我应该如何防止这种情况?