我在heroku上创建了一个Django应用程序.我无法正确迁移heroku服务器.在过去,我已在本地完成所有makemigrations,然后将它们推送到服务器.它过去曾奏效.现在我想我会选择在服务器端进行全部迁移,因为我根本没有在本地运行这个应用程序.
我刚刚在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()
将更改推送到服务器后,我运行了以下输出:
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
好像对不对?那么我尝试迁移,因为你知道实际上会在数据库中创建表:
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.
无论我多少次尝试重新运行makemigrations然后迁移它似乎仍然没有拿起它.不知道为什么会发生这种情况除了以这种方式无法在heroku服务器上运行之外?我肯定需要在本地进行makemigrations并推送吗?
仅供参考我只是在settings.py中定义了默认的sqlite3数据库.
我遇到了类似的问题.我只是用ssh进入heroku dyno:
heroku运行bash(来自你的heroku应用程序文件夹ofc)如果需要,可以使用createsuperuser运行所有migration和makemigration命令.适用于sqlite和postgre.
精彩评论