81👍
This is my Procfile and it is working exactly as you describe:
release: python manage.py migrate
web: run-program waitress-serve --port=$PORT settings.wsgi:application
See Heroku docs on defining a release process:
https://devcenter.heroku.com/articles/release-phase#defining-a-release-command
The release command is run immediately after a release is created, but before the release is deployed to the app’s dyno formation. That means it will be run after an event that creates a new release:
- An app build
- A pipeline promotion
- A config var change
- A rollback
- A release via the platform API
The app dynos will not boot on a new release until the release command finishes successfully.
If the release command exits with a non-zero exit status, or if it’s shut down by the dyno manager, the release will be discarded and will not be deployed to the app’s formation.
Be aware, however, this feature is still in beta.
Update:
When you have migrations that remove models and content types, Django requires a confirmation in the console
The following content types are stale and need to be deleted:
…
Any objects related to these content types by a foreign key will also be deleted. Are you sure you want to delete these content types? If you’re unsure, answer ‘no’. Type ‘yes’ to continue, or ‘no’ to cancel:
The migrate command in your Procfile does not respond and the release command fails. In this scenario, remove the migrate line, push live, run the migrate command manually, then add it back for future deploys.
32👍
The migrate does automatically runs on Heroku, but for now you can safely do it once your dyno is deployed with heroku run python manage.py migrate
.
If production, you can put your app in maintenance first with heroku maintenance:on --app=<app name here>
- [Django]-Tying in to Django Admin's Model History
- [Django]-Django queries: how to filter objects to exclude id which is in a list?
- [Django]-How to use UUID
5👍
Setup your Procfile like in the docs
release: python manage.py migrate
web: gunicorn myproject.wsgi --log-file -
documented at https://devcenter.heroku.com/articles/release-phase#specifying-release-phase-tasks
- [Django]-How does the order of mixins affect the derived class?
- [Django]-Django 1.8 – what's the difference between migrate and makemigrations?
- [Django]-Django AutoField with primary_key vs default pk
3👍
You can create a file bin/post_compile
which will run bash commands after the build.
Note that it is still considered experimental.
Read here for more buildpack info.
See here for an example
Alternatively, Heroku is working on a new Releases feature, which aims to simplify and solve this process. (Currently in Beta).
Good luck!
- [Django]-How can I disable logging while running unit tests in Python Django?
- [Django]-How do I include image files in Django templates?
- [Django]-Get protocol + host name from URL