python - 为什么我会收到“CommandError:App 'app_name' 没有迁移。” 使用 Heroku 时?
问题描述
所以我已经将我的 Django 项目部署到 Heroku,现在尝试迁移数据库。我在本地服务器上一切正常。然后我尝试在heroku中运行命令,如下所示。
heroku run python manage.py makemigrations app_name'
.
这工作得很好。
Migrations for 'app_name':
contents\migrations\0001_initial.py
- Create model Book
- Create model Category
- Create model Content
然后当然,我试过了:heroku run python manage.py migrate app_name
。
但是后来我收到了这个错误CommandError: App 'app_name' does not have migrations.
,我已经对可能的问题进行了一些研究,但这些都与我的无关。
例如,我确实__init__.py
在migrations
app_name 目录内的文件夹中。另外,我也试过heroku run python manage.py migrate
了heroku run python manage.py migrate app_name
。
我很困惑。你认为是什么问题?提前致谢。:)
解决方案
As explained in heroku's help article Why are my file uploads missing/deleted?:
The Heroku filesystem is ephemeral - that means that any changes to the filesystem whilst the dyno is running only last until that dyno is shut down or restarted.
That is you do generate the migration files but they cease to exist shortly after when the app is reloaded.
In general the strategy you take is not a good approach to migrations as this can cause various issues, let's say you have multiple production servers each generates their own migrations this causes a conflict! In your situation suppose you do migrate this way and then later you want to add some new models this again will cause you problems.
One should always add their migrations to the version control (git, etc.) commit them and push them to production (here your heroku dyno). That is run python manage.py makemigrations
locally, commit the generated migrations, push them and then run heroku run python manage.py migrate
.
推荐阅读
- image-processing - 用于比较二值图像的度量
- android - Flutter:如何使用 RaisedButton 在 PageView 中导航或使用按钮移动 pageViewController
- java - 如何在 Spring Boot 应用程序中编写静态资源文件
- python - 在 Django 管理面板中加载页面时将字段值初始化为 null
- laravel - 请求 Laravel 雄辩的结构或其他方式
- arrays - 获取 cosmos db 中数组中不包含的结果
- mybatis - ibatis地图列表
进入@Result - python - 在命令提示符下使用 pip 时出现语法错误
- python-3.x - Numpy 无法访问列
- c - BMA253 加速度计芯片 ID 接收错误