django makemigrations和在heroku服务器上迁移不会创建表 [英] django makemigrations and migrate on heroku server don't create tables

查看:46
本文介绍了django makemigrations和在heroku服务器上迁移不会创建表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Python版本2.7
Django版本1.9.7

Python Version 2.7 Django Version 1.9.7

我在heroku上创建了Django应用。我无法让heroku服务器正确地迁移。过去,我在本地完成所有 makemigrations ,然后将它们推送到服务器。过去一直有效。现在,我以为我会选择在服务器端全部迁移,因为我根本不在本地运行此应用程序。

I have created a Django app on heroku. I can't get the heroku server to migrate properly. In the past I have done all the makemigrations locally and then pushed them to the server. It has worked in the past. Now I thought I would choose to do the migrations all on the server side, since I am not running this app locally at all.

我刚刚在 models.py 中为应用 main创建了一个新模型:

I just created one new model inside the models.py for app 'main':

from __future__ import unicode_literals

from django.db import models

class InstagramPhotos(models.Model):
    imageId = models.IntegerField()
    userId = models.IntegerField()
    likes = models.IntegerField()
    captionText = models.CharField(max_length=200)
    image = models.ImageField()

将更改推送到服务器后,我运行了此命令,结果如下:

After pushing changes to the server, I ran this, with following output:

heroku run python manage.py makemigrations main




运行python manage.py makemigrations主要基于⬢
glacial-beach-50253 ... up,run.8354 Migrations for'main':

0001_initial.py:
-创建模型InstagramPhotos

似乎可以吗?因此,然后我尝试进行迁移,这实际上将在数据库中创建表:

Seems ok right? So then I try to migrate which as you know will actually create the tables in the DB:

heroku run python manage.py migrate




正在运行python manage.py在⬢glacial-beach-50253上进行迁移...向上,运行$ b $b。7556执行的操作:应用所有迁移:auth,
contenttypes,admin,sessions正在运行的迁移:否迁移到
即可。
。您的模型所做的更改尚未反映在
迁移中,因此不会应用。运行'manage.py makemigrations'
进行新的迁移,然后重新运行'manage.py migration'来应用

Running python manage.py migrate on ⬢ glacial-beach-50253... up, run.7556 Operations to perform: Apply all migrations: auth, contenttypes, admin, sessions Running migrations: No migrations to apply. Your models have changes that are not yet reflected in a migration, and so won't be applied. Run 'manage.py makemigrations' to make new migrations, and then re-run 'manage.py migrate' to apply them.

无论我尝试过多少次重新运行 makemigrations ,然后再执行 migration 它似乎仍然没有捡起来。除了无法以这种方式在heroku服务器上操作之外,不确定为什么会发生这种情况吗?我肯定需要在本地执行 makemigrations 并进行推送吗?

No matter how many times I have tried to re-run the makemigrations and then migrate it still seems to not pick it up. Not sure why this is happening besides it is just not possible to operate on heroku server this way? Do I definitely need to do makemigrations locally and push?

仅供参考,我只是仍在其中定义了默认的sqlite3数据库 settings.py

FYI I just have the default sqlite3 DB still defined in settings.py.

推荐答案

我遇到了类似的问题。

我只是将 ssh 放入heroku dyno中,其中:
heroku run bash (从您的heroku应用程序文件夹ofc中)

I just ssh into heroku dyno with: heroku run bash ( from your heroku application folder ofc )

如果需要,可以使用createsuperuser运行所有迁移和makemigration命令。
对我来说可以与sqlite和postgre一起使用。

Than run all the migration and makemigration commands with createsuperuser if needed. Works with sqlite and postgre for me.

这篇关于django makemigrations和在heroku服务器上迁移不会创建表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆