【问题标题】:How can i solve a migration issue in django project hosted on heroku?如何解决 Heroku 上托管的 django 项目中的迁移问题?
【发布时间】:2016-10-08 20:46:32
【问题描述】:

我的项目托管在 heroku 上,最近我想更改一列的大小 在数据库中 但是在运行 ma​​kemigrations 命令和 migrate 命令后,它给出了一个错误,我不想丢失我的数据。

   H:\shuboy2014>heroku run python manage.py makemigrations posts
   Running python manage.py makemigrations posts on shuboy2014... up, run.9067
   Migrations for 'posts':
     0003_auto_20160608_1404.py:
       - Alter field slug on post       

   H:\shuboy2014>heroku run python manage.py migrate
   Running python manage.py migrate on shuboy2014... up, run.3731
   Operations to perform:
     Apply all migrations: admin, contenttypes, posts, sessions, auth
   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.

任何有用的建议都将不胜感激。

【问题讨论】:

  • 您确定您的更改已反映在迁移文件中吗?
  • 但是我如何在 heroku 上查看它?
  • 无论如何,您都应该将迁移文件提交到源代码管理,我不确定您在这里问什么
  • @Sayse 我直接在服务器上运行迁移命令,这就是为什么我的迁移没有反映在数据库上。
  • 但是你永远不需要在服务器上运行makemigrations

标签: python django heroku django-models


【解决方案1】:

heroku run 命令在带有临时文件系统的 One-Off Dynos 上运行,因此您在立即销毁的文件系统上生成迁移文件。

您应该在本地生成迁移,提交并推送它们,然后执行heroku run python manage.py migrate 命令。

【讨论】:

    【解决方案2】:

    我只是在本地计算机上运行 ma​​kemigrationsmigrate 命令,然后将其推送到 heroku 并再次运行这两个命令并完成。

     H:\shuboy2014>heroku run python manage.py migrate
     Running python manage.py migrate on shuboy2014... up, run.6192
     Operations to perform:
       Apply all migrations: contenttypes, auth, posts, sessions, admin
     Running migrations:
       Rendering model states... DONE
       Applying posts.0003_auto_20160608_2001... OK
    

    【讨论】:

      猜你喜欢
      • 2016-10-05
      • 2018-10-23
      • 2018-08-01
      • 2021-07-13
      • 2017-03-02
      • 1970-01-01
      • 2020-02-06
      • 2021-12-25
      • 1970-01-01
      相关资源
      最近更新 更多