gpt4 book ai didi

python - heroku 服务器上的 django makemigrations 和 migrate 不创建表

转载 作者:太空狗 更新时间:2023-10-30 00:34:51 24 4
gpt4 key购买 nike

Python 2.7 版Django 版本 1.9.7

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

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

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

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

最佳答案

我遇到了类似的问题。

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

然后在需要时使用 createsuperuser 运行所有迁移和 makemigration 命令。为我使用 sqlite 和 postgre。

关于python - heroku 服务器上的 django makemigrations 和 migrate 不创建表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38330432/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com