Kieran
Kieran

Reputation: 3965

Applying Django migrations in a non-interactive environment

I've renamed some models in Django and created the migrations using python manage.py makemigrations.

When using python manage.py migrate, I get prompted with the following message

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:

On my local machine, I can simply type 'yes'. However, my application is deployed on Heroku and I have configured migrations to run automatically when the application is built. I achieve this using a post_compile file that looks like this:

# Run Django migrations
./manage.py migrate

# Compress static assets
./manage.py compress

Will the migration simply fail to complete as a consequence of not being in an interactive shell (and therefore not being able to answer 'yes' to this question)? If so, how can this problem be avoided?

Upvotes: 4

Views: 3072

Answers (1)

Selcuk
Selcuk

Reputation: 59164

You can use the --noinput command line argument of migrate command:

./manage.py migrate --noinput

This would suppress the prompt, but will not delete stale content types (ie. it works as if you answered No at the prompt). See Django ticket #25036 .

Another alternative would be to use the Unix command yes (I am not sure if it is enabled on Heroku by default though):

yes "yes" | ./manage.py migrate

Upvotes: 9

Related Questions