简体   繁体   中英

Django Migration Error in Heroku, but migrate correctly in heroku local

Python 3.5, Django 1.10.3, Sqlite
I have deployed a django app in heroku.It ran correctly before. One day I make some change in 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. 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.
It is my first question in stackoverflow.com, and English is not my tongue. 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 run bash
./manage.py makimigrations
./manage.py migrate 

and all work succhess!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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