django makemigrations to rename field without user input
Asked Answered
J

2

6

I have a model with CharField named oldName. I want to rename the field to newName.

When I run python manage.py makemigrations, I get a confirmation request "Did you rename model.oldName to model.newName (a CharField)? [y/N]"

However, I want to run the whole thing inside a docker container and there is no provision to provide the user input. Is there a way to force the migration without need for user input?

PS: I tried --noinput option with makemigrations. In this case migrations are not getting applied.

Jarita answered 5/10, 2016 at 5:54 Comment(7)
Migrations applied with migrate command.Indentation
I ran the migrate command after makemigrationsJarita
Why would you want to do this inside docker? Migrations are part of your source code.Indentation
That would be an option too. Even if I want to do it outside, is it possible to skip the user input part. It would help if there are lot of such instances.Jarita
Try doing this script_or_command < <(yes y).Indentation
This helped me. Thank you :)Jarita
You are welcome. Moved to answerIndentation
I
1

Use

script_or_command < <(yes y)

But I'm not sure this will work for multiple input prompts.

Indentation answered 5/10, 2016 at 6:24 Comment(3)
where should i add this sentence? if my docker-compose.yml file has this command bash -c "python manage.py makemigrations && python manage.py migrate && python manage.py runserver 0.0.0.0:8000"Rh
@Rh in your case it is better to use --no-input option for makemigrations. bash -c "python manage.py makemigrations --no-input && python manage.py migrate && python manage.py runserver 0.0.0.0:8000".Indentation
@Rh Also I suggest not using this pattern for makemigrations. It should be reviewed and applied manuallyIndentation
P
4

Added yes and pipe | before command

python manage.py makemigrations

inside the docker-compoase.yaml file and it should work as shown below:

yes | python manage.py makemigrations
Prey answered 17/11, 2021 at 12:42 Comment(0)
I
1

Use

script_or_command < <(yes y)

But I'm not sure this will work for multiple input prompts.

Indentation answered 5/10, 2016 at 6:24 Comment(3)
where should i add this sentence? if my docker-compose.yml file has this command bash -c "python manage.py makemigrations && python manage.py migrate && python manage.py runserver 0.0.0.0:8000"Rh
@Rh in your case it is better to use --no-input option for makemigrations. bash -c "python manage.py makemigrations --no-input && python manage.py migrate && python manage.py runserver 0.0.0.0:8000".Indentation
@Rh Also I suggest not using this pattern for makemigrations. It should be reviewed and applied manuallyIndentation

© 2022 - 2024 — McMap. All rights reserved.