在 Heroku 上部署 Python(2.7)/Django(1.5) 应用程序时出现数据库完整性错误

Database integrity errors when deploying Python(2.7)/Django(1.5) app on Heroku

这些天我正在通过开发一个 reddit 克隆来学习 Python(2.7)/Django(1.5)。克隆几乎完成并且在我的本地环境 (db = sqlite3) 中完美运行。但是当我尝试在 Heroku (db = postgres) 上托管相同的东西时,事情出了问题。

具体而言,网络应用程序仍会加载,但 loginlogoutcomments 部分抛出错误(我正在使用 django-registrations-redux、django-comments 和 south)。

由于应用程序已上线,您可以直接到此处查看错误跟踪:

我的所有文件,包括 requirements.txt 等,都可以在这里找到:https://github.com/mhb11/unconnectedredditapp

让我感到困惑的是,这个东西在本地继续完美运行,但在 Heroku 上却不行。我假设我可能捏造了南方移民。但是,我整天都在删除我的 Heroku 应用程序并设置新的应用程序。每次我在新应用程序上 运行 syncdb 命令时,在设置超级用户凭据 post Django-auth 系统安装和 table 创建后,我都会收到以下错误:

DatabaseError: relation "links_userprofile" does not exist
LINE 1: ...rofile"."user_id", "links_userprofile"."bio" FROM "links_use...

我用 heroku run python2.7 manage.py syncdb --migrate 跟进(即 syncdb 和 migrate 一起),这次迁移不会喷出错误。但是无论如何,该应用程序仍然会出现我在开始时指出的数据库错误。

我想我应该在我的本地设置中卸载 South,并使用旧的 syncdb 来处理一切。

在这一点上,我的 heroku 部署可能会出错,所以我知道您可能无法给我一个精确的解决方案。但是请用你的所有想法来打动我——我愿意尝试一切,因为这件事现在已经困扰我 48 小时了。求助!

注意:如果您最终签出了克隆版 (https://salty-ridge-5419.herokuapp.com/),请原谅文本标签不是英文的。


执行 git push heroku master:

后 运行ning syncdb 命令 的错误跟踪
(unconnectedreddit)has@has-VirtualBox:~/Desktop/uncreddit$ heroku run python2.7 manage.py syncdb
Running `python2.7 manage.py syncdb` attached to terminal... up, run.8792
CHECKING_HEROKU!
ON_HEROKU!
Syncing...
Creating tables ...
Creating table auth_permission
Creating table auth_group_permissions
Creating table auth_group
Creating table auth_user_groups
Creating table auth_user_user_permissions
Creating table auth_user
Creating table django_content_type
Creating table django_session
Creating table django_site
Creating table django_admin_log
Creating table django_comments
Creating table django_comment_flags
Creating table south_migrationhistory

You just installed Django's auth system, which means you don't have any superusers defined.
Would you like to create one now? (yes/no): yes
Username (leave blank to use 'u8919'): mhb
Email address: bhs@bhs.com
Password: 
Password (again): 
DatabaseError: relation "links_userprofile" does not exist
LINE 1: ...rofile"."user_id", "links_userprofile"."bio" FROM "links_use...

问题已通过 运行 heroku config:set ON_HEROKU=1 解决。在我的 settings.py 文件中,我在本地使用了 sqlite3,但在 Heroku 上恢复为 postgres。将 ON_HEROKU 设置为 1 before 运行 syncdb,因此,解决了我的问题。