Reputation: 41
In server while deploying any project I want to give different database name in settings.py on django structure.Where I have to change database name??
My docker-compose.yml file as following..
version: '3'
services:
db:
image: postgres
web:
build: .
command: bash -c "python manage.py makemigrations && python manage.py migrate && python manage.py runserver 0.0.0.0:8000"
volumes:
- .:/code
ports:
- "8000:8000"
depends_on:
- db
my database configuration is like this in settings.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'postgres',
'USER': 'postgres',
'HOST': 'db',
'PORT': 5432,
}
}
Where I have to change database name??
Upvotes: 1
Views: 51
Reputation: 8076
You can use the POSTGRES_DB environment variable. From Postgres docker image docs:
POSTGRES_DB This optional environment variable can be used to define a different name for the default database that is created when the image is first started. If it is not specified, then the value of POSTGRES_USER will be used.
The docker-compose.yml file would be:
version: '3'
services:
db:
image: postgres
env:
POSTGRES_DB: <DATABASE NAME>
web:
build: .
command: bash -c "python manage.py makemigrations && python manage.py migrate && python manage.py runserver 0.0.0.0:8000"
volumes:
- .:/code
ports:
- "8000:8000"
depends_on:
- db
-
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': '<DATABASE NAME>',
'USER': 'postgres',
'HOST': 'db',
'PORT': 5432,
}
}
Upvotes: 2