简体   繁体   English

Heroku中的Django迁移错误,但在heroku本地中正确迁移

[英]Django Migration Error in Heroku, but migrate correctly in heroku local

Python 3.5, Django 1.10.3, Sqlite Python 3.5、Django 1.10.3、Sqlite
I have deployed a django app in heroku.It ran correctly before.我已经在 heroku 中部署了一个 django 应用程序。它之前运行正常。 One day I make some change in models.py .有一天,我在models.py做了一些改变。 I first do我先做

python manage.py collectstatic  
python manage.py makemigrations  
python manage.py migrate
heroku local web -f Procfile.windows

, ,
the app run correctly in local.该应用程序在本地正确运行。 Then I push my code to heroku.然后我将我的代码推送到 heroku。 I ran:我跑了:

git push heroku master
heroku run bash
python manage.py makemigrations
python manage.py migrate
heroku ps:scale web=1

But server returned:但服务器返回:

ProgrammingError at /twitter/blog/
column twitter_article.enable_comments does not exist
LINE 1: ...article"."content", "twitter_article"."pub_date", "twitter_a...
                                                         ^
Request Method: GET
Request URL:    https://super-pershing.herokuapp.com/twitter/blog/
Django Version: 1.10.3
Exception Type: ProgrammingError
Exception Value:    
column twitter_article.enable_comments does not exist
LINE 1: ...article"."content", "twitter_article"."pub_date", "twitter_a...
                                                         ^
Exception Location: /app/.heroku/python/lib/python3.5/site-packages/django/db/backends/utils.py in execute, line 64
Python Executable:  /app/.heroku/python/bin/python
Python Version: 3.5.1
Python Path:    
['/app',
 '/app/.heroku/python/bin',
 '/app',
 '/app/.heroku/python/lib/python35.zip',
 '/app/.heroku/python/lib/python3.5',
 '/app/.heroku/python/lib/python3.5/plat-linux',
 '/app/.heroku/python/lib/python3.5/lib-dynload',
 '/app/.heroku/python/lib/python3.5/site-packages',
 '/app/.heroku/python/lib/python3.5/site-packages/setuptools-28.8.0-py3.5.egg',
 '/app/.heroku/python/lib/python3.5/site-packages/pip-9.0.1-py3.5.egg']
Server time:    Sat, 3 Dec 2016 11:03:58 +0800

Error during template rendering

In template /app/twitter/templates/twitter/blog.html, error at line 7
column twitter_article.enable_comments does not exist LINE 1: ...article"."content", "twitter_article"."pub_date", "twitter_a... ^
1   {% extends 'twitter/base.html' %}
2   {% load bootstrap3 %}
3   
4   {% block bootstrap3_content %}
5   {{ block.super }}
6   <div class="container">
7     {% if article_list %}
8       <ul>
9       {% for article in article_list %}
10        <li>
11          <h3><a href="/twitter/blog/{{ article.id }}/">{{ article.title }}</a></h3>
12        </li>
13      {% endfor %}
14      </ul>
15    {% else %}
16      <h3><strong>No Blog here</strong></h3>
17    {% endif %}

Here is my key model:这是我的关键模型:

    from django.db import models
    from fluent_comments.moderation import moderate_model,comments_are_open, comments_are_moderated
    from fluent_comments.models import get_comments_for_model, CommentsRelation

    class Article(models.Model) :
    title = models.CharField(max_length = 100)
    category = models.CharField(max_length = 50, blank = True)
    content = models.TextField(blank = True, null = True)
    pub_date = models.DateTimeField("pub_date")
    enable_comments = models.BooleanField("Enable comments", default=True)

    def __str__(self) :
        return self.title

    class Meta:
        ordering = ['-pub_date']

    # Optional, give direct access to moderation info via the model:
    comments = property(get_comments_for_model)
    comments_are_open = property(comments_are_open)
    comments_are_moderated = property(comments_are_moderated)

    # Give the generic app support for moderation by django-fluent-comments:
    moderate_model(Article,
        publication_date_field='pub_date',
        enable_comments_field='enable_comments',
    )

If I drop my database and build a new database.如果我删除我的数据库并建立一个新数据库。 Server won't report error.服务器不会报错。 Why?为什么? I'm using sqlite.我正在使用sqlite。
It is my first question in stackoverflow.com, and English is not my tongue.这是我在 stackoverflow.com 上的第一个问题,英语不是我的语言。 If there is some wrong in my word ,please forgive me and give me some advice.如果我的话有什么错误,请原谅我并给我一些建议。

I had such problem and spent a lot of time to solve, so: problem with CLI of Heroku and to need use bash:我遇到了这样的问题,花了很多时间来解决,所以:Heroku 的 CLI 问题,需要使用 bash:

heroku run bash
./manage.py makimigrations
./manage.py migrate 

and all work succhess!一切顺利!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM