When I try to connect my app to postgresql db I always get this same error:
django.core.exceptions.ImproperlyConfigured: 'django.db.backends.postgresql' isn't an available database backend.
Try using 'django.db.backends.XXX', where XXX is one of:
'mysql', 'oracle', 'sqlite3'
Here is my code in settings
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'mydb',
'USER': 'postgres',
'PASSWORD': 'pass123',
'HOST': 'localhost',
'PORT': '5432'
}
}
I am using django version 3.0.2 and my psycopg2 version 2.8.5 . I did downgrade to earlier version of django and still the problem persists. Also my python version is 3.8.
I tried doing this too
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'mydb',
'USER': 'postgres',
'PASSWORD': 'pass123',
'HOST': 'localhost',
'PORT': '5432'
}
}
I thought it was the issue with the virtual env so I decided to perform on other projects too but still does not work. Can anyone please help me.
I fixed it by uninstalling the psycopg2. I installed psycopg2-binary.
pip install psycopg2-binary
Related
I want to set the mysql database using mysql-connector-python for setting up a web site made with Django using a database backend but I get this error:
django.core.exceptions.ImproperlyConfigured: 'mysql.connector.django' isn't an available database backend.
Try using 'django.db.backends.XXX', where XXX is one of:
'mysql', 'oracle', 'postgresql', 'sqlite3'
My credentials (name, user, password, host, port) works fine, so the problem isn't here.
DATABASES = {
'default': {
'ENGINE': 'mysql.connector.django',
'NAME': 'library',
'USER': 'username',
'PASSWORD': 'password',
'HOST': '127.0.0.1',
'PORT': '3306',
'OPTIONS': {
'autocommit': True,
'use_pure': True,
},
}
}
I'm using python 3.8.5 and mysql-connector-python 8.0.21 and I understand that mysql-connector-python, starting from version 8.0.13, has a bug, which makes it impossible to use with Django and to avoid the bug I added ‘use_pure’: True in database options. But it doesn't work.
I found this question but it doesn't say anything about using ‘use_pure’: True.
If the mysql-connector-python isn't compatible with python 3, what can I use instead? (I can't wait for the support release).
you do not have the option to use mysql connector, you have to install mysql-client from https://www.lfd.uci.edu/~gohlke/pythonlibs/#mysqlclient and try installing all the wheels incase you get errors, while installing using pip install
Am trying to use MySQL with Django 2.0, I have installed it using "pip install mysqlclient" and it installed successfully. What do i need to do next?
In settings.py you'll need:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'db_name',
'USER': 'user_name',
'PASSWORD': 'user_password',
'HOST': 'localhost',
'PORT': '3306',
}
You'll need to create the db and user and grant permissions within MySQL.
You'll also need to ensure you have MySQL setup and running.
I'm trying to configure Django with PostgreSQL on Windows Server 2012.
but after a while i get this error
only protocol 3 supported
I'm using Postgres 9.6 and psycopg2 2.7.3 and Django 1.11 and mod_wsgi.
i also tried Postgres 9.5 and psycopg2 2.6 but did not work
In settings.py I have
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'mydb',
'USER': 'postgres',
'PASSWORD': 'mypassword',
'HOST': 'localhost',
'PORT': '5432',
}
}
i read this question and also this question but did not found any solutions.
Do you know any solutions for the problem?
i installed xampp server. I want to access MySQL database through python. I tried to install MySQL-python package. It needs visual studio which I don't want to install.
I tried through MySQL connectors, but it is not allowing to do so.
How can I access MySQL database through python?
You can try like this,
db=MySQLdb.connect(user="user_name",passwd="password",db="database_name",unix_socket="mysql.sock file path")
OR try running, python manage.py runserver
OR once check your default setting of database
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'database_name', # Or path to database file if using sqlite3.
'USER': 'user_name', # Not used with sqlite3.
'PASSWORD': 'password', # Not used with sqlite3.
'HOST': '127.0.0.1', # Set to empty string for localhost. Not used with sqlite3.
'PORT': '3306' # Set to empty string for default. Not used with sqlite3.
}
}
I am using MySql db.i made following changes but now i am getting following error
DATABASES = {
'default': {
'NAME': 'test',
'ENGINE': 'sqlserver_ado',
'HOST':'127.0.0.1',
'USER': 'mssql',
'PASSWORD': 'mssql',
'PORT': '1434'
}
}
"ImportError: No module named 'django.db.backends.util' "
You've probably installed django-mssql version 1.7 which supports <= Django 1.8.
You can try django-mssql-1.8b2:
pip install django-mssql==1.8b2
Beware that this is probably a beta version, so it might not be suitable for you.
The error means that you don't have suitable db backends for mssql. You can install https://github.com/lionheart/django-pyodbc as db backend.