7
The recommended way to use MySQL with Django is to install mysqlclient
instead of mysql-connector-python
.
If you use mysql-connector-python
, then you need to change the ENGINE
to 'mysql.connector.django'
in your DATABASES setting (docs).
DATABASES = {
'default': {
'ENGINE': 'mysql.connector.django',
'HOST': 'xxxxxx.compute.amazonaws.com',
'PORT': '3306',
'NAME': 'xxxxx',
'USER': 'xxxxx',
'PASSWORD': 'xxxxxx',
'init_command': "SET sql_modes = 'STRICT_TRANS_TABLES'",
},
}
6
pip install PyMySQL
Django: settings.py
import pymysql
pymysql.install_as_MySQLdb()
Source code pymysql.__init__.py
def install_as_MySQLdb():
"""
After this function is called, any application that imports MySQLdb or
_mysql will unwittingly actually use pymysql.
"""
sys.modules["MySQLdb"] = sys.modules["_mysql"] = sys.modules["pymysql"]
- [Django]-Django Model: Meta: how to have default ordering case-insensitive
- [Django]-Django creates the test database for Postgresql with incorrect sequences start values
- [Django]-Celery tasks not works with gevent
- [Django]-Django ImageField [Errno 13] Permission denied even though directory is writable
- [Django]-Django 1.3 β can't register my custom UserAdmin
1
you need to instsall missing pkg by running this on ubuntu and then restart mysql
sudo apt-get install libmysqlclient-dev python-dev
sudo /etc/init.d/mysql restart
- [Django]-Celery tasks not works with gevent
- [Django]-Django can't syncdb after drop/create database
- [Django]-Why does the Django Atom1Feed use atom:updated instead of atom:published?
- [Django]-Django: Sum by date and then create extra field showing rolling average
- [Django]-Setting up Django website on a shared hosting
0
I just had this problem .
you should use
sudo apt-get install libmysqlclient-dev
if it said the package is missing then try :
sudo apt-get install libmariadb-dev
Source:stackexchange.com