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.

2 Answers2

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
Erick
  • 1,408
  • 14
  • 19
1

Use

script_or_command < <(yes y)

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

Sardorbek Imomaliev
  • 14,861
  • 2
  • 51
  • 63
  • 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"` – Bito Jan 27 '22 at 18:39
  • 1
    @Bito 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"`. – Sardorbek Imomaliev Jan 28 '22 at 05:03
  • @Bito Also I suggest not using this pattern for `makemigrations`. It should be reviewed and applied manually – Sardorbek Imomaliev Jan 28 '22 at 05:05