0

我有一个问题,希望有见识的人可以提供帮助。我的第一个 Django 项目即将完成,我目前正在过渡到 Postgres 数据库,以期通过 Heroku 进行部署。在我运行 python manage.py syncdb 之前,这个过程进行得相当顺利。

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-profiles,我在设置时遇到了一些问题,这些问题显然很常见。“缺失手册”站点 - http://birdhouse.org/blog/2009/06/27/django-profiles/ - 帮助解决了这些问题,但可能导致了当前的问题。

我正在使用那里推荐的 signals.post_save.connect(create_profile, sender=User) 。我正在研究可能出了什么问题,并在 Google Groups 上看到了这篇文章并回答说“如果你在 User 上使用 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)
4

1 回答 1

1

这里似乎有些可疑:

INSERT INTO “report_userprofile” (“user_id”, “first_name”, “…

这两个字段是本机 User 模型上的字段,而不是自定义 Profile 模型上的字段。为什么要尝试将这些字段插入到您的 Profile 表中?

是否还有更多代码没有在这里显示?

环顾四周,我看到了一些有趣的替代方法来自动创建个人资料记录:

http://djangosnippets.org/snippets/500/ http://www.turnkeylinux.org/blog/django-profile

但我知道您使用的技术(在 Birdhouse 中列出)对于我构建的每个 Django 站点都运行良好,所以我对此并不特别怀疑。

于 2012-07-06T06:46:56.897 回答