Heroku migrate failure counts as a success

When “python manage.py migrate” in Heroku fails, CircleCi reports it as a success:

Here’s the full output:

heroku run python manage.py migrate --app myappname
Running python manage.py migrate on myappname… starting, run.6945
Running python manage.py migrate on myappname… connecting, run.6945
Running python manage.py migrate on myappname… up, run.6945
Operations to perform:
Apply all migrations: sessions, contenttypes, admin, web, auth
Running migrations:

Rendering model states… DONE
Applying web.0004_auto_20160503_2002… OK
Applying web.0005_order_monthly_minutes_usage… OK
Applying web.0006_auto_20160503_2003… OK
Applying web.0007_user… OK
Applying web.0008_order_user…Traceback (most recent call last):
File “/app/.heroku/python/lib/python3.5/site-packages/django/db/backends/utils.py”, line 64, in execute

return self.cursor.execute(sql, params)

psycopg2.IntegrityError: insert or update on table “web_order” violates foreign key constraint "web_order_user_id_ea2d4a3f_fk_web_user_id"
DETAIL: Key (user_id)=(1) is not present in table “web_user”.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):

File “manage.py”, line 9, in
execute_from_command_line(sys.argv)
File “/app/.heroku/python/lib/python3.5/site-packages/django/core/management/init.py”, line 353, in execute_from_command_line
utility.execute()
File “/app/.heroku/python/lib/python3.5/site-packages/django/core/management/init.py”, line 345, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File “/app/.heroku/python/lib/python3.5/site-packages/django/core/management/base.py”, line 348, in run_from_argv

self.execute(*args, **cmd_options)

File “/app/.heroku/python/lib/python3.5/site-packages/django/core/management/base.py”, line 399, in execute

output = self.handle(*args, **options)

File “/app/.heroku/python/lib/python3.5/site-packages/django/core/management/commands/migrate.py”, line 200, in handle

executor.migrate(targets, plan, fake=fake, fake_initial=fake_initial)

File “/app/.heroku/python/lib/python3.5/site-packages/django/db/migrations/executor.py”, line 92, in migrate
self._migrate_all_forwards(plan, full_plan, fake=fake, fake_initial=fake_initial)
File “/app/.heroku/python/lib/python3.5/site-packages/django/db/migrations/executor.py”, line 121, in _migrate_all_forwards

state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)

File “/app/.heroku/python/lib/python3.5/site-packages/django/db/migrations/executor.py”, line 198, in apply_migration

state = migration.apply(state, schema_editor)

File “/app/.heroku/python/lib/python3.5/site-packages/django/db/backends/base/schema.py”, line 90, in exit

self.execute(sql)

File “/app/.heroku/python/lib/python3.5/site-packages/django/db/backends/base/schema.py”, line 110, in execute

cursor.execute(sql, params)

File “/app/.heroku/python/lib/python3.5/site-packages/django/db/backends/utils.py”, line 64, in execute

return self.cursor.execute(sql, params)

File “/app/.heroku/python/lib/python3.5/site-packages/django/db/utils.py”, line 95, in exit

six.reraise(dj_exc_type, dj_exc_value, traceback)

File “/app/.heroku/python/lib/python3.5/site-packages/django/utils/six.py”, line 685, in reraise

raise value.with_traceback(tb)

File “/app/.heroku/python/lib/python3.5/site-packages/django/db/backends/utils.py”, line 64, in execute

return self.cursor.execute(sql, params)

django.db.utils.IntegrityError: insert or update on table “web_order” violates foreign key constraint “web_order_user_id_ea2d4a3f_fk_web_user_id”

DETAIL: Key (user_id)=(1) is not present in table “web_user”.

Here’s the relevant circle.yml

machine:
python:
version: 3.5.1
pre:
- curl -L -O https://s3-external-1.amazonaws.com/circle-downloads/circle-pyenv-python-3.5.1_1.0_amd64.deb
- sudo dpkg -i circle-pyenv-python-3.5.1_1.0_amd64.deb
deployment:
staging:
branch: staging
commands:
- heroku maintenance:on --app myappname
- “[[ ! -s “$(git rev-parse --git-dir)/shallow” ]] || git fetch --unshallow”
- git push git@heroku.com:myappname.git $CIRCLE_SHA1:refs/heads/master
- heroku run python manage.py migrate --app myappname
- heroku maintenance:off --app myappname