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

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

问题描述

Python 2.7 版Django 1.9.7 版

我在 heroku 上创建了一个 Django 应用程序.我无法让 heroku 服务器正确地migrate.过去我在本地完成了所有的makemigrations,然后将它们推送到服务器.它在过去有效.现在我想我会选择在服务器端进行迁移,因为我根本没有在本地运行这个应用程序.

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

from __future__ import unicode_literals从 django.db 导入模型类 InstagramPhotos(models.Model):imageId = models.IntegerField()userId = models.IntegerField()喜欢 = models.IntegerField()captionText = models.CharField(max_length=200)图像 = 模型.ImageField()

在将更改推送到服务器后,我运行了它,输出如下:

heroku run python manage.py makemigrations main

<块引用>

在⬢上运行 python manage.py makemigrations mainglacial-beach-50253... up, run.8354 'main' 的迁移:
0001_initial.py:- 创建模型 InstagramPhotos

看起来没问题吧?那么我尝试 migrate ,正如你所知,它实际上会在数据库中创建表:

heroku 运行 python manage.py migrate

<块引用>

在 ⬢ glacial-beach-50253 上运行 python manage.py migrate...向上,run.7556 要执行的操作:应用所有迁移:auth、contenttypes、admin、sessions 运行迁移:没有迁移到应用.您的模型有更改尚未反映在迁移,因此不会被应用.运行'manage.py makemigrations'进行新的迁移,然后重新运行manage.py migrate"以应用

无论我尝试重新运行 makemigrationsmigrate 多少次,它似乎仍然没有找到它.除了无法以这种方式在 heroku 服务器上运行之外,不知道为什么会发生这种情况?我是否一定需要在本地执行 makemigrations 并推送?

仅供参考,我在 settings.py 中仍然定义了默认的 sqlite3 DB.

解决方案

我遇到了类似的问题.

我只是 ssh 进入 heroku dyno:heroku run bash(来自您的 heroku 应用程序文件夹 ofc)

如果需要,请使用 createsuperuser 运行所有迁移和 makemigration 命令.为我使用 sqlite 和 postgre.

Python Version 2.7 Django Version 1.9.7

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.

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

Running python manage.py makemigrations main on ⬢ glacial-beach-50253... up, run.8354 Migrations for 'main':
0001_initial.py: - Create model 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

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.

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?

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

解决方案

I had a similar problem.

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

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

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

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