Skip to content

Instantly share code, notes, and snippets.

@kylefox kylefox/
Last active Aug 30, 2019

What would you like to do?
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.
echo "=> Performing database migrations..."
python migrate

This comment has been minimized.

Copy link

ebarojas commented Sep 22, 2016

This is great, works like a charm ->

I added a conditional env var in order to control whether you want this in all your environments:

if [ $AUTO_MIGRATE == True ]; then
  echo "=> Performing database migrations..."
  python 'app_name'/ migrate

This comment has been minimized.

Copy link

wooyek commented Dec 29, 2016

I may state the obvious, but to help anyone who gets here looking to solve No such file or directory error…

Make sure you have LF line endings!


This comment has been minimized.

Copy link

freezed commented Oct 20, 2018

This solution may be outdated with the release option of the Procfile.

See StackOverflow answer or Heroku doc.

git push heroku ersatz-model:master 


remote: Compressing source files... done.
remote: Building source:
remote: -----> Python app detected
remote:        Using supported version of Python 3.6 (python-3.6.6)
remote: -----> Installing requirements with pip
remote: -----> $ python collectstatic --noinput
remote:        120 static files copied to '/tmp/…/staticfiles', 376 post-processed.
remote: -----> Discovering process types
remote:        Procfile declares types -> release, web
remote: -----> Compressing...
remote:        Done: 56.5M
remote: -----> Launching...
remote:  !     Release command declared: this new release will not be available until the command succeeds.
remote:        Released v41
remote:        https://… deployed to Heroku
remote: Verifying deploy... done.
remote: Running release command...
remote: Operations to perform:
remote:   Apply all migrations: admin, auth, contenttypes, ersatz, sessions
remote: Running migrations:
remote:   Applying ersatz.0006_auto_20181020_0053... OK
remote: Waiting for release.... done.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.