On my windows machine, I have following packages installed in my app.
django: 1.9.9
pyodbc==4.0.3
django-pyodbc-azure==1.10.4.0
In my settings.py file..
DATABASES = {
'default': {
'ENGINE': 'sql_server.pyodbc',
'NAME': os.environ.get('DB_NAME'),
'USER': os.environ.get('DB_USERNAME'),
'PASSWORD': os.environ.get('DB_PASSWORD'),
'HOST': 'tcp:sdohsandbox.database.windows.net',
'PORT': '1433',
'OPTIONS': {
'driver': 'SQL Server Native Client 11.0',
'MARS_Connection': 'True',
},
'CONN_MAX_AGE': 120,
}
}
When I start server I am getting following error..
django.core.exceptions.ImproperlyConfigured: Django 1.9.9 is not supported.
Though I have latest version of pyodbc I am getting error.
Need help.
You have installed a version of django-pyodbc-azure that does not support Django 1.10. The project page on pypi says:
If you want to use it on older versions of Django, specify an appropriate version number (1.9.x.x for Django 1.9) at installation like this:
pip install "django-pyodbc-azure<1.10"
Related
I am trying to switch my Django database from SQLite3 to PostgreSQl, so I follow many tutorials to install and setup Postgres with Django project.
I did the following: pip install psycopg2, pip install psycopg2-binary and I modified the settings.py like that:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': BASE_DIR / 'db.postgresql',
'USER': 'muusername',
'PASSWORD': 'mypassword',
'HOST': '127.0.0.1',
'PORT': '5432'
}
}
Finally I maked my database, by running the command python manage.py makemigrations.
However, I got this error:
django.core.exceptions.ImproperlyConfigured: 'django.db.backends.postgresql' isn't an available database backend or couldn't be imported. Check the above exception. To use one of the built-in backends, use 'django.db.backends.XXX', where XXX is one of:
'mysql', 'oracle', 'sqlite3'
Please note that I am also seccesufully install the pgAdmin in my OS which is Windows 10 in a first step.
I know that the problem is related by configuration of Postgres in my django project, but I don't know how to fix it, also I checked my djnago version which is the latest one, also, all needed packages are installed in my venv.
You cannot add like this in postgres:
'NAME': BASE_DIR / 'db.postgresql', #You got that error because of this. This setting is for only sqlite3 not for postgres
Just add db_name in NAME:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'your_db_name', #add your db name here
'USER': 'postgres',
'PASSWORD': 'your_db_password',
'HOST': '127.0.0.1',
'PORT': '5432',
}
}
Make sure you have actually downloaded the PostgreSQL installer itself and installed it.
I solve this problem by just upgrade the django, as you can see here in the exception:
django.core.exceptions.ImproperlyConfigured: 'django.db.backends.postgresql' isn't an available database backend or couldn't be imported. Check the above exception. To use one of the built-in backends, use 'django.db.backends.XXX', where XXX is one of:
'mysql', 'oracle', 'sqlite3'
Django ask the user to use mysql, oracle or sqlite3, but not the case of postgresql.
So this exception will be fixed when the user upgrade the django version.
I hope this answer can be helpful for someone another.
When running the command: python manage.py runserver I'm getting the following error:
django.db.utils.OperationalError: (2059, "Authentication plugin 'caching_sha2_password' cannot be loaded: The specified module could not be found.\r\n")
These are the relevant settings:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'polls',
'USER': 'root',
'PASSWORD': '<my-password>',
'HOST': 'localhost'
}
}
I've seen solutions that went around the problem, such as in this thread. They suggest changing the engine to mysql.connector.django, however the engine recommended by django is mysqlclient and therefore I would like to use it.
Other suggestion were to use naive password instead of sha2. I'd rather not go with this solution for security reasons.
Versions:
mysql 8.0.17 for Win64 on x86_64 (MySQL Community Server - GPL)
python 3.7.4
Django 2.2.4
mysqlclient 1.4.4
Try
ALTER USER 'root'#'localhost' IDENTIFIED WITH mysql_native_password BY '<my-password>';
I'm trying to make the migrations between my database (MySQL) and Django. I used the same parameters in Linux and didn't have any problems. Now I'm using the command :
python manage.py migrate
and I get nothing at all on the terminal. However, the command works if I let the default parameters ( for a sqlite database ). Also, I've noticed that it actually reads the 'settings.py' file because it returns an error if I write something that doesn't make any sense. Here are my parameters, I know for sure that they are correct ( I checked with the MySQL commands ).
settings.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'my_db',
'USER': 'root',
'PASSWORD': '123456789_dont_judge_me',
'HOST': '127.0.0.1',
'PORT': '3306',
}
}
Error message
I'm using Windows 10, Python 3.5 and Django 2.0.
Do you have any idea where the problem could come from ?
Thank you for your responses kind people !
You can try this.
Note: I am not claiming it is best solution, but it is working for me
in case of Window10.
Step1 : Install pymysql
pip install pymysql
Step2: Edit settings.py
settings.py
---------------
import os
import pymysql
pymysql.install_as_MySQLdb()
import MySQLdb
# Database
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'django_test',
'USER': 'root',
'PASSWORD': '123456',
'HOST': '127.0.0.1',
'PORT': '3306',
}
}
Step3: migrate it
python manage.py migrate
you can follow this link
I'm a Django newby (I started yesterday) and I'm trying to configure the DB. But since I think I'll always be using Django with MySQL I want to set it up. I read the doc and I saw that in order to use MySQL you have to install a module, and so I did. I installed mysqlclient since installing MySQLdb with pip return:
$ pip2 install mysqldb
Could not find a version that satisfies the requirement mysqldb (from versions: )
No matching distribution found for mysqldb
and the Oracle solution isn't working at all (django don't recognize it).
So I entered my credentials, and it look like this in project's settings.py:
DATABASES = {
'default': {
# 'ENGINE': 'django.db.backends.sqlite3',
# 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
'ENGINE': 'django.db.backends.mysql',
'NAME': 'dbname_entered_and_tested',
'USER': 'username_entered_and_tested',
'PASSWORD': 'correct_password',
'HOST': 'externale.domain_name_to_db.com',
'PORT': '3306',
}
}
So it returned me
$ python manage.py runserver
... 30 lines of Exceptions ...
django.db.utils.OperationalError: (2026, 'SSL connection error: error:00000001:lib(0):func(0):reason(1)')
So I googled and I found Django AWS RDS MySQL Error: (2026, 'SSL connection error: error:00000001:lib(0):func(0):reason(1)')
So I set my settings to:
DATABASES = {
'default': {
# 'ENGINE': 'django.db.backends.sqlite3',
# 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
'ENGINE': 'django.db.backends.mysql',
'NAME': 'dbname_entered_and_tested',
'USER': 'username_entered_and_tested',
'PASSWORD': 'correct_password',
'HOST': 'externale.domain_name_to_db.com',
'PORT': '3306',
'OPTIONS': {
'skip-ssl',
},
}
}
And it returned me
$ python manager.py runserver
... 30 lines of Exceptions ...
ValueError: dictionary update sequence element #0 has length 8; 2 is required
So I managed to generate my own certificats after reading another stackoverflow post, using OpenSSL and the MySQL doc (https://dev.mysql.com/doc/refman/5.6/en/creating-ssl-files-using-openssl.html) and I succeded, but django threw the same:
django.db.utils.OperationalError: (2026, 'SSL connection error: error:00000001:lib(0):func(0):reason(1)')
I already tried connecting with multiple other clients to my db using the same credentials, disabling SSL, enabling SSL, another user account.
I found a solution but it involve downgrading the MySQL version to 5.6.27 (Django server not starting correctly seems to be a mysql issue.) and it won't be a problem... if I only could :C . The MySQL database since to be a pain for a lot of Django users (so much post talking about that out there ...) and I'm just a newbie but I don't want to be discouraged by a simple bug and stop Django :S So, does someone have an answer ?
EDIT: I'm using the latest version of both django, pip and mysqlclient
I have successfully followed the Django 1.4 Tutorial 1-4 (the poll system) and now its running until I deploy it in Apache Webserver 2.2 using Postgres Database. Everytime I access localhost I always have "Internal Server Error" but if I use MySQL as my database everything is ok. What do you think is wrong? Did I miss something to configure in Postgre?
Here is my database connection settings in Mysql(Working) and in Postgre(Not Working), both using Apache2.2 + mod_wsgi.so
//Postgre
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'django_demo1',
'USER': 'postgres',
'PASSWORD': 'mypassword',
'HOST': 'localhost',
'PORT': '',
}
}
//MySQL
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'django_demo1',
'USER': 'root',
'PASSWORD': 'mypassword',
'HOST': 'localhost',
'PORT': '',
}
}
Other INFO:
OS: windows 7, Python: 2.7, Django: 1.4, Postgre 9.1
If you are able to access MySQL but not Postgres, I guess psycopg2 which is the Postgres adapter for python is not installed. Install psycopg2 using pip.
pip install psycopg2
Here is the pypi.