如何解决在heroku上托管的django项目中的迁移问题?

问题描述:

我的项目托管在Heroku最近我想换一列 的大小分贝 但运行makemigrations命令后,然后迁移命令时,它给出了一个错误,我不想失去我的数据。如何解决在heroku上托管的django项目中的迁移问题?

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. 

任何有用的建议将是可观的。

+0

您确定您的更改已反映在迁移文件中吗? – AndreyT

+0

但我如何才能在heroku上查看它? – shuboy2014

+0

无论如何,您应该将迁移文件提交到您的源代码管理,我不确定您在这里问的是什么 – Sayse

heroku run命令上一次性DYNOS有一个短暂的文件系统中运行,所以你生成被立即销毁的文件系统上的迁移文件。

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

我就跑makemigrations我的本地计算机上迁移命令,然后将其推在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