I am getting django database connection error - django

DATABASE_OPTIONS = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'student',
'USER': 'root',
'PASSWORD': 'pooja',
'HOST': 'localhost',
'PORT': 3306,
'init_command': 'SET storage_engine=INNODB, SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED'
},
}
Exception IS:
raise ImproperlyConfigured("settings.DATABASES is improperly configured. "
django.core.exceptions.ImproperlyConfigured: settings.DATABASES is improperly configured. Please supply the ENGINE value. Check settings documentation for more details.
I am using mysql database I am getting above exception in django while migrating model to the database please let me know what is the error what i ma doing wrong here.
thanks you for your reply

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'student',
'USER': 'root',
'PASSWORD': 'pooja',
'HOST': 'localhost',
'PORT': 3306,
'init_command': 'SET storage_engine=INNODB, SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED'
},
}

Related

SyntaxError: EOL while scanning string literal (I am trying to connect Django with PostgreSQL)

I am trying to connect Django to the PostgreSQL database, but this is my first time doing it, so I am not sure how exactly to do it. The problem seems to be with the line, where the password is.
settings.py -
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': '<db_name>',
'USER': '<db_username>',
'PASSWORD: '<password>',
'HOST': 'db_hostname_or_ip>',
'PORT': 'db_port',
}
}
When I try to make migrations in my prompt, (python manage.py makemigrations) I am getting the error mentioned in the title. Can anybody help me please?
Your code
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': '<db_name>',
'USER': '<db_username>',
'PASSWORD: '<password>',
'HOST': 'db_hostname_or_ip>',
'PORT': 'db_port',
}
}
What it actually should be
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': '<db_name>',
'USER': '<db_username>',
'PASSWORD': '<password>',
'HOST': 'db_hostname_or_ip>',
'PORT': 'db_port',
}
}
Actually you're forgetting the closing qoute after PASSWORD

Specify the --ssl option for django database connection

When I connect to my database with mysql I specify the option --ssl, or else I get the error
SSL connection is required. Please specify SSL options and retry.
I know that with MySQL you can connect with a ssl certificate where you have a copy of the certificate locally. With this approach I know how to move forward with Django, as you can specify the option as described here https://stackoverflow.com/a/12285601/2889451
However, in my case I simply pass the option --ssl, and I don't have a local copy of the certificate.
How can I enable this option in Django?
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': DB_NAME,
'USER': DB_USER,
'PASSWORD': DB_PASSWORD,
'HOST': DB_HOST,
'PORT': '',
}
}
Apparently you can solve it by passing the options as shown below:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': DB_NAME,
'USER': DB_USER,
'PASSWORD': DB_PASSWORD,
'HOST': DB_HOST,
'PORT': '',
'OPTIONS': {'ssl': True},
}
}

i am getting error while giving my ip and localhost name in postgres admin

I am getting error while giving my IP address and localhost name in PostgreSQL admin, any help would be appreciated.
You can take a look at my PostgreSQL admin image here:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'myproject',
'USER': 'myprojectuser',
'PASSWORD': 'fakepassword',
'HOST': 'localhost',
'PORT': '',
}
}

Django - Adding a second database entry causes failure. Django no longer uses 'default'

My database and project work great using this database setting:
DATABASES = {
'default': {
'ENGINE': 'django.contrib.gis.db.backends.postgis',
'NAME': 'myprojectdb',
'USER': 'myprojectuser',
'PASSWORD': 'my_secret_password',
'HOST': 'localhost',
'PORT': '5432',
'ATOMIC_REQUESTS': True
},
}
But I want to add a 'readonly' database entry for my readonly db user, like this, so that I can run django-sql-explorer:
DATABASES = {
'default': {
'ENGINE': 'django.contrib.gis.db.backends.postgis',
'NAME': 'myprojectdb',
'USER': 'myprojectuser',
'PASSWORD': 'my_secret_password',
'HOST': 'localhost',
'PORT': '5432',
'ATOMIC_REQUESTS': True
},
'readonly': {
'ENGINE': 'django.contrib.gis.db.backends.postgis',
'NAME': 'myprojectdb',
'USER': 'myprojectreadonly',
'PASSWORD': 'your_eyes_only_secret',
'HOST': 'localhost',
'PORT': '5432',
'ATOMIC_REQUESTS': True
}
}
And now django throws a couple different errors. If I try to do anything with migrations, I get:
django.db.utils.ProgrammingError: permission denied for relation django_migrations
If I try to runserver, I get:
"AUTH_USER_MODEL refers to model '%s' that has not been installed" % settings.AUTH_USER_MODEL
django.core.exceptions.ImproperlyConfigured: AUTH_USER_MODEL refers to model 'users.User' that has not been installed
It seems like when I add the second database setting, django is attempting to use that for migrations, running the server, etc, even though it's not 'default'
If I comment out the second entry, everything works great again.
Any recommendations on how to correct this?
Edit: If I change the settings to use the same username and password, everything works great, so it's not just an issue of django being confused on names. IE:
DATABASES = {
'default': {
'ENGINE': 'django.contrib.gis.db.backends.postgis',
'NAME': 'myprojectdb',
'USER': 'myprojectuser',
'PASSWORD': 'my_secret_password',
'HOST': 'localhost',
'PORT': '5432',
'ATOMIC_REQUESTS': True
},
'readonly': {
'ENGINE': 'django.contrib.gis.db.backends.postgis',
'NAME': 'myprojectdb',
'USER': 'myprojectuser',
'PASSWORD': 'my_secret_password',
'HOST': 'localhost',
'PORT': '5432',
'ATOMIC_REQUESTS': True
}
}
The two configurations shares the same database names 'NAME': 'myprojectdb'
So when you try to migrates dbname seems to conflicts so the applications is having an indecision on which to use The previous or the later

Django - Using PostGIS database with PostgreSQL database, do I need 2 databases?

I'm currently using a single PostgreSQL database, with standard settings.
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'postgres',
'USER': 'postgres',
'PASSWORD': password,
'HOST': 'localhost',
'PORT': '',
}
}
My question is, can I keep using the default postgres setup, and just perform CREATE EXTENSION postgis in the shell to get access to postgis features? Or do I need to add a postgis database separately, like below:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'postgres',
'USER': 'postgres',
'PASSWORD': password,
'HOST': 'localhost',
'PORT': '',
}
'geodata': {
'ENGINE': 'django.contrib.gis.db.backends.postgis',
'NAME': 'geodjango',
'USER': 'geo',
},
}
You can keep using the default postgres setup, just changing the engine to: django.contrib.gis.db.backends.postgis
DATABASES = {
'default': {
'ENGINE': 'django.contrib.gis.db.backends.postgis',
'NAME': 'postgres',
'USER': 'postgres',
'PASSWORD': password,
'HOST': 'localhost',
'PORT': '',
}
}