加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

python – django makemigrations和heroku服务器上的迁移不会创

发布时间:2020-12-20 11:52:47 所属栏目:Python 来源:网络整理
导读:Python版本2.7 Django版本1.9.7 我在heroku上创建了一个Django应用程序.我无法正确迁移heroku服务器.在过去,我已在本地完成所有makemigrations,然后将它们推送到服务器.它过去曾奏效.现在我想我会选择在服务器端进行全部迁移,因为我根本没有在本地运行这个应
Python版本2.7
Django版本1.9.7

我在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.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读