簡體   English   中英

Heroku中的Django遷移錯誤,但在heroku本地中正確遷移

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

Python 3.5、Django 1.10.3、Sqlite
我已經在 heroku 中部署了一個 django 應用程序。它之前運行正常。 有一天,我在models.py做了一些改變。 我先做

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

,
該應用程序在本地正確運行。 然后我將我的代碼推送到 heroku。 我跑了:

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

但服務器返回:

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 %}

這是我的關鍵模型:

    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',
    )

如果我刪除我的數據庫並建立一個新數據庫。 服務器不會報錯。 為什么? 我正在使用sqlite。
這是我在 stackoverflow.com 上的第一個問題,英語不是我的語言。 如果我的話有什么錯誤,請原諒我並給我一些建議。

我遇到了這樣的問題,花了很多時間來解決,所以:Heroku 的 CLI 問題,需要使用 bash:

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

一切順利!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM