我的项目托管在heroku上,最近我想改变一列的大小 在db 但是在运行 makemigrations 命令然后迁移命令后,它会出错并且我不想丢失我的数据。
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 :(得分:3)
heroku run
命令在具有临时文件系统的One-Off Dynos上运行,因此您将在立即销毁的文件系统上生成迁移文件。
您应该在本地生成迁移,提交和推送它们,然后执行heroku run python manage.py migrate
命令。
答案 1 :(得分:1)
我只是在本地计算机上运行 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