Answer the question
In order to leave comments, you need to log in
Why doesn't the python manage.py migrate command exit after running and return control to the console?
I am trying to solve the following problem. There is an application on Django and I need to implement the launch of this application through Docker. As a database, we connect a container with PostgreSQL or MySQL. When running through docker-compose, you need to make sure that Django creates the necessary tables in the database before starting the Django application. To do this, in the docker-compose.yml file, in the comand attribute, before the server start command, we write the python manage.py migrate command. This command creates all the necessary tables, but after execution, the process does not end and, in fact, does not allow the next command to run.
some lines....
web_1 | Applying datapage.0001_initial... OK
web_1 | Applying datapage.0002_auto_20190709_1955... OK
web_1 | Applying datapage.0003_auto_20190713_1358... OK
web_1 | Applying datapage.0004_auto_20190720_1107... OK
web_1 | Applying sessions.0001_initial... OK
docker-compose exec web python manage.py migrate
some lines....
Applying auth.0009_alter_user_last_name_max_length... OK
Applying datapage.0001_initial... OK
Applying datapage.0002_auto_20190709_1955... OK
Applying datapage.0003_auto_20190713_1358... OK
Applying datapage.0004_auto_20190720_1107... OK
Applying sessions.0001_initial... OK
^CException ignored in: <module 'threading' from '/usr/local/lib/python3.7/threading.py'>
Traceback (most recent call last):
File "/usr/local/lib/python3.7/threading.py", line 1307, in _shutdown
lock.acquire()
KeyboardInterrupt
version: '3'
services:
web:
build: .
command: >
bash -c "
sleep 40 &&
python manage.py migrate --noinput &&
python manage.py runserver 0.0.0.0:8000 --noreload"
ports:
- '8000:8000'
depends_on:
- db
db:
image: mysql:5.7
ports:
- '3306:3306'
environment:
MYSQL_DATABASE: 'db_django'
MYSQL_ROOT_PASSWORD: 'password'
restart: always
No changes detected
(Жмём Cntrl+C)
^CException ignored in: <module 'threading' from '/usr/local/lib/python3.7/threading.py'>
Traceback (most recent call last):
File "/usr/local/lib/python3.7/threading.py", line 1307, in _shutdown
lock.acquire()
KeyboardInterrupt
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question