django makemigrations和heroku服务器上的迁移不会创建表

时间:2021-11-01 21:22:53

Python Version 2.7 Django Version 1.9.7

Python版本2.7 Django版本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.

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

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

我刚刚在models.py中为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

运行python manage.py makemigrations main on⬢glacial-beach-50253 ... up,run.8354'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

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.

在⬢clcial-beach-50253上运行python manage.py migrate ...运行.7556要执行的操作:应用所有迁移:auth,contenttypes,admin,sessions运行迁移:不应用任何迁移。您的模型具有尚未在迁移中反映的更改,因此不会应用。运行'manage.py makemigrations'进行新的迁移,然后重新运行'manage.py migrate'以应用它们。

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?

无论我多次试图重新运行makemigrations然后迁移它仍然似乎没有拿起它。不知道为什么会发生这种情况除了以这种方式无法在heroku服务器上运行之外?我绝对需要在本地做makemigrations并推送吗?

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

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

1 个解决方案

#1


4  

I had a similar problem.

我有类似的问题。

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

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

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

如果需要,可以使用createsuperuser运行所有migration和makemigration命令。适用于我的sqlite和postgre。

#1


4  

I had a similar problem.

我有类似的问题。

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

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

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

如果需要,可以使用createsuperuser运行所有migration和makemigration命令。适用于我的sqlite和postgre。