Skip to content

Instantly share code, notes, and snippets.

@kylefox
Last active October 23, 2020 08:42
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kylefox/7044491259b6b2586ca1 to your computer and use it in GitHub Desktop.
Save kylefox/7044491259b6b2586ca1 to your computer and use it in GitHub Desktop.
Run Django database migrations after deploy to Heroku. This file must live at `bin/post_compile` within your root project directory.
# !/usr/bin/env bash
# File path should be ./bin/post_compile
# (.sh extension added in Gist just to enable shell syntax highlighting.
# https://discussion.heroku.com/t/django-automaticlly-run-syncdb-and-migrations-after-heroku-deploy-with-a-buildpack-or-otherwise/466/7
echo "=> Performing database migrations..."
python manage.py migrate
@AbdouTlili
Copy link

i think you can just use the release command in your Procfile
for exemple to migrate :

release: python manage.py migrate
web: gunicorn django_proj.wsgi --log-file -

or runs a script :

release: ./ post_compile.sh
web: gunicorn django_proj.wsgi --log-file -

the command release runs after :

  • A successful app build
  • A change to the value of a config var (unless the config var is associated with an add-on)
  • A pipeline promotion
  • A rollback
  • A release via the platform API
  • Provisioning a new add-on

@segunisreal
Copy link

segunisreal commented Jun 10, 2020

Just do:

release: python manage.py migrate --no-input
web: gunicorn project_name.wsgi

and you will be fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment