Django迁移未推向Heroku

时间:2019-08-20 21:09:03

标签: django heroku django-models heroku-postgres

我更新了Django博客,以使用子弹式URL <slug:slug>/而不是ID <int:pk>/。我还将slugField添加到Article模型,并将所有href转换为article.slug。 Ran迁移和本地一切正常。但是,当我推送到Heroku时遇到错误。

这就是我尝试保存新文章时发生的情况。


ProgrammingError at /admin/articles/article/
column articles_article.slug does not exist
LINE 1: ...ticles_article"."id", "articles_article"."title", "articles_...
                                                             ^
Request Method: GET
Request URL:    https://***********.herokuapp.com/admin/articles/article/
Django Version: 2.1.4
Exception Type: ProgrammingError
Exception Value:    
column articles_article.slug does not exist
LINE 1: ...ticles_article"."id", "articles_article"."title", "articles_...
                                                             ^

我检查了我的Heroku Postgress数据库,发现即使进行了迁移,也没有添加新的slug列。我不确定下一步该怎么做。我目前正在寻找手动更新heroku postgress的方法,但是如果有一种侵入性较小的方法来解决此问题,我将不知所措。

2 个答案:

答案 0 :(得分:1)

首先验证迁移已执行(heroku)

verify that the last migration of the article model is in the django_migrations table

如果找不到它,请确保您已更新了迁移(本地)

python manage.py makemigrations

在数据库生产(heroku)中运行迁移

heroku run python manage.py migrate

答案 1 :(得分:0)

您碰巧先进行迁移然后再进行迁移吗?上面的评论向后指出了这一点。另外,您确定将迁移应用于生产数据库吗?它要求将设置标志添加到迁移命令中,以指向您的生产设置/数据库位置。