Django mysqlclient not installed - python

I was working with sqlite database in local development .
After uploading project to server ubuntu , i installed mysqlclient , but when i try to run makemigrations command this error occurred :
ImportError: No module named 'django.db.backends.mysql'
Try using 'django.db.backends.XXX', where XXX is one of:
'oracle', 'postgresql', 'sqlite3'
When I try to install mysqlclient again , this message will shown :
Requirement already satisfied: mysqlclient in
/home/user/Env/project/lib/python3.5/site-packages (1.3.13)
I also checked project env folder and mysql lib exists in env/python3.5/site-packages !
settings database :
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'dbname',
'USER': 'user',
'PASSWORD': 'pass',
'HOST': 'localhost',
'PORT': '',
}
}

install pymysql in your python package manager, and add write in your settings.py
import pymysql
pymysql.version_info = (1, 3, 13, "final", 0)
pymysql.install_as_MySQLdb()

Related

django.db.backends.postgresql error when try to makemigrations my django project

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.

why django not found module psycopg2 in django2.2 and python 3.8

I install django 2.2.10 and python 3.8 and psycopg2 2.8.4 but when i try migration with command (python manage.py migrate) confront this error:
raise ImproperlyConfigured("Error loading psycopg2 module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading psycopg2 module: No module named 'psycopg2'
psycopg2 in 32-bit. i try any solution that available in stackoverflow but this error don't dissolve
databases in settings.py:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'postgres',
'USER': 'seyyedh',
'PASSWORD' : '123456',
'HOST':'localhost',
'PORT' : '5432',
}
}
Edit:
Sorry, I didn't read your config.
If you are using Postgresql, your Engine-Setting should be 'django.db.backends.postgresql', not 'django.db.backends.postgresql_psycopg2':
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'postgres',
'USER': 'seyyedh',
'PASSWORD' : '123456',
'HOST':'localhost',
'PORT' : '5432',
}
}
as seen here. You probably shouldn't use the initial postgres DB (as referenced in "NAME"), but create a new database for your django project.
Initial answer:
Are you by chance using another python environment than the one configured for your project?
E.g., if you created a virtual environment for you project and have that configured for running the application etc. in your IDE, but for the migration call you are using the python system environment.
If you open the interactive shell for the python environment you are using for migration, and type:
help('modules')
psycopg2 has to be listed!
pip install psycopg2-binary
(or)
pip install psycopg2 for <2.8 psycopg2 versions
(or)
sudo apt-get install python-psycopg2
I understand that psycopg2 installed on another virtual env while main virtual env running
so I unistalled that virtual env and error solved

Django 2.1.5 on Windows. After runserver: System check identified no issues (0 silenced)

This message showed after I executed runserver command:
System check identified no issues (0 silenced)
I have referenced this solution, but it didn't work for me(I start my mysql server by the command
"C:\Program Files\MySQL\MySQL Server 8.0\bin\mysqld"
).
Here is the background information(the "pip list" command):
(DjangoEnv) D:\pythonproject\DjangoEnv\loginoutonly>pip list
Package Version
Django 2.1.5
mysqlclient 1.3.13
pip 18.1
PyMySQL 0.9.3
pytz 2018.9
setuptools 40.6.3
wheel 0.32.3
Here is the db information in settings.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'loginoutonly',
'USER': 'root',
'PASSWORD': 'pwd',
'HOST': 'localhost',
'PORT': '3306'
}
}
XAMPP helped me.
XAMPP says that
Port 3306 in use by "Unable to open process"!
I change my MySQL port to 3307 using XAMPP [Config] button.
Then, I change my settings.py code to
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'loginoutonly',
'USER': 'root',
'PASSWORD': '',
'HOST': 'localhost',
'PORT': '3307'
}
}
I also need to test the MySQL WorkBench connection of this newly connected port "3307".

Error loading MySQLdb

I'm facing problem while connecting mysql database in django. I'm getting error as
raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: DLL load failed: %1 is not a valid Win32 application.
I have set database setting as
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'db_name',
'USER': 'user',
'PASSWORD': 'password',
'HOST': 'localhost', # Or an IP Address that your DB is hosted on
'PORT': '3306',
}
}
I don't know where I'm making mistake.
Probably you are using 64bit python/mysql but pip had installed the 32bit mysql-python.
Download the 64bit mysql-python from the link [The link only has support for python 2.7]:
http://www.codegood.com/archives/129
and run the following:
$ pip install path_to_64bit-mysql-python.zip

Psycopg2 installation for OS X and Django

I would like to use the PostGreSQL database with Django.
I first installed the driver psycopg2 with pip and virtualenv:
$ PATH=$PATH:/Library/PostgreSQL/9.3/bin/
$ pip install psycopg2
[...]
Successfully installed psycopg2
Cleaning up...
$
I have done the following configuration in Django:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'my_db',
'USER': 'django',
'PASSWORD': 'xx',
'HOST': 'localhost',
'PORT': '5432',
}
}
But when I try to create the schema with syncdb I have the following error:
$ python manage.py syncdb
raise ImproperlyConfigured("Error loading psycopg2 module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading psycopg2 module: dlopen([...]/Code/env/dev/lib/python2.7/site-packages/psycopg2/_psycopg.so, 2): Library not loaded: libssl.1.0.0.dylib
Referenced from: [...]Code/env/dev/lib/python2.7/site-packages/psycopg2/_psycopg.so
Reason: image not found
Do you know why the libssl is not loaded and how can I fix this issue?
Thank you

Categories

Resources