我有一个问题,希望有见识的人可以帮助。我的第一个Django项目已接近完成,我正在过渡到Postgres数据库,以期通过Heroku进行部署。这个过程相当顺利,直到我运行python manage.py syncdb时才发生。Django:转换为Postgres数据库时缺失配置文件表
django.db.utils.DatabaseError: relation “report_userprofile” does not exist
LINE 1: INSERT INTO “report_userprofile” (“user_id”, “first_name”, “…
显然,它没有为UserProfile模型创建数据库表。现在我得到这个例外,当我尝试运行服务器:
Exception Type: DoesNotExist at /accounts/login/
Exception Value: Site matching query does not exist.
在我使用该项目的附加应用是Django的配置文件,我遇到了一些问题,建立这显然是常见的。 “遗失手册”网站 - http://birdhouse.org/blog/2009/06/27/django-profiles/ - 帮助解决了这些问题,但可能导致了当前的问题。
我在这里使用了signals.post_save.connect(create_profile,sender = User)。我正在研究可能发生了什么问题,并在Google网上论坛中发现了这篇文章,并回答说“如果您在用户上使用post_save信号,则无法这样做,因为它会导致竞争状况。” ,不知道这可能会导致此问题,显然这将是最好的解决,并得到这些表到新的数据库和运作。
任何深入了解如何解决这个问题,将不胜感激。
这是可能导致问题的数据库模型:
class UserProfile(models.Model):
user = models.OneToOneField(User, unique=True, related_name="profile")
first_name = models.CharField(max_length=25)
last_name = models.CharField(max_length=35)
email = models.EmailField()
birth_date = models.DateField(blank=True, null=True)
city = models.CharField(max_length=25)
state = models.CharField(max_length=20)
zip_code = models.CharField(max_length=10)
profile_pic = models.ImageField(upload_to='profilepictures', blank=True)
def __unicode__(self):
return " %s" % (self.user)
def get_absolute_url(self):
return ('profiles_profile_detail',(), { 'username': self.user.username })
get_absolute_url = models.permalink(get_absolute_url)
signals.post_save.connect(create_profile, sender=User)