28๐
You are using the dj-database-url
module to set DATABASES['default']
. Whatever comes before the line:
DATABASES['default'] = dj_database_url.config()
is meaningless as you replace your database configuration in its entirety. The dj_database_url.config()
loads your database configuration from the DATABASE_URL
environment variable, or returns {}
if the variable is not set.
Judging by your error, you didnโt set the DATABASE_URL
at all. Judging by the code preceding the dj_database_url.config()
line, you should not be using the dj_database_url.config()
function at all.
If you did want to use it, at least build a default URL:
if ON_HEROKU:
DATABASE_URL = 'postgresql://<postgresql>'
else:
DATABASE_URL = 'sqlite:///' + os.path.join(BASE_DIR, 'db.sqlite3')
DATABASES = {'default': dj_database_url.config(default=DATABASE_URL)}
8๐
You can use following setting for localhost
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'DatabaseName',
'USER': 'DatabaseUserName',
'PASSWORD': 'DatabaseUserpassword',
'HOST': 'localhost',
'PORT': '5432',
}
}
- [Django]-Django serializer for one object
- [Django]-Invalid command WSGIDaemonProcess Deploy Django application on CentOS 6.7
- [Django]-Find Monday's date with Python
3๐
Encountered this issue when running my github workflows with github actions. So I found the following work around:
POSTGRES_DB = os.environ.get("POSTGRES_DB") #database name
POSTGRES_PASSWORD = os.environ.get("POSTGRES_PASSWORD") # database user password
POSTGRES_USER = os.environ.get("POSTGRES_USER") # database username
POSTGRES_HOST = os.environ.get("POSTGRES_HOST") # database host
POSTGRES_PORT = os.environ.get("POSTGRES_PORT") # database port
POSTGRES_READY = (
POSTGRES_DB is not None
and POSTGRES_PASSWORD is not None
and POSTGRES_USER is not None
and POSTGRES_HOST is not None
and POSTGRES_PORT is not None
)
print(POSTGRES_READY)
if POSTGRES_READY:
DATABASES = {
"default": {
"ENGINE": "django.db.backends.postgresql",
"NAME": POSTGRES_DB,
"USER": POSTGRES_USER,
"PASSWORD": POSTGRES_PASSWORD,
"HOST": POSTGRES_HOST,
"PORT": POSTGRES_PORT,
}
}
Then your .env
file:
export DEBUG=True
export DJANGO_SECRET_KEY=CI_CD_TEST_KEY
export POSTGRES_USER=taxi
export POSTGRES_PASSWORD=taxi
export POSTGRES_DB=pdm
export POSTGRES_PORT=5432
export POSTGRES_HOST=localhost
Then run source .env
- [Django]-A Better Django Admin ManyToMany Field Widget
- [Django]-Handling race condition in model.save()
- [Django]-Django: ModelMultipleChoiceField doesn't select initial choices
2๐
I had the same issue using django-tenant-users
when running the command:
python manage.py setup_dtu_tenants
It was because I had a folder named "settings" inside my project folder at the same level as my settings.py
. After removing this folder, the issue is gone.
- [Django]-Heroku โ No module named wsgi
- [Django]-Celery parallel distributed task with multiprocessing
- [Django]-How to write setup.py to include a Git repository as a dependency
0๐
With "Django==3.1.7", I got the same error when using the code below in "settings.py":
# "settings.py"
from django.db import connection
print(connection.queries) # Causes error
So, I removed "print(connection.queries)" as shown below, then the error was solved:
# "settings.py"
from django.db import connection
# print(connection.queries) # Causes error
- [Django]-Django templates: loop through and print all available properties of an object?
- [Django]-How to use csrf_token in Django RESTful API and React?
- [Django]-How to store empty value as an Integerfield