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?
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
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
I have this installed for mysql and django , still I receive an error
-Django 2.1.3
-mysql-connector-python 8.0.13
-pip 18.1
-pytz 2018.7
-setuptools 39.0.1
-virtualenv 16.0.0
-virtualenvwrapper-win 1.2.5
-wheel 0.32.3
How can I connect to mysql and django with mysql-connector. I still receive an error to install mysqlclient. Is there anything missing. please let me know
If you do not have MySQL installed. follow up here:
But first, check if these tutorials apply for your current OS version! The installation process can be different
example:
Ubuntu 14, 16 or 18.
Mac osx 10.12 Sierra, 10.13 High Sierra or 10.14 mojave
Windows:
https://chocolatey.org/packages?q=mysql
Ubuntu:
https://www.digitalocean.com/community/tutorials/how-to-use-mysql-or-mariadb-with-your-django-application-on-ubuntu-14-04
Mac osx:
https://gist.github.com/operatino/392614486ce4421063b9dece4dfe6c21
With MySQL up and running, log into the interactive session for MySQL
mysql -u root -p
create your database user
CREATE DATABASE myproject CHARACTER SET UTF8;
CREATE USER myprojectuser#localhost IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON myproject.* TO myprojectuser#localhost;
FLUSH PRIVILEGES;
now in myproject/myproject/settings.py apply these changes:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'myproject',
'USER': 'myprojectuser',
'PASSWORD': 'password',
'HOST': 'localhost',
'PORT': '',
}
}
Update your DATABASES setting to use the connector backend.
DATABASES = {
'default': {
'NAME': 'user_data',
'ENGINE': 'mysql.connector.django',
...
},
...
}
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 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.
}
}