简体   繁体   中英

How to use MySQL as DB for a django project?

I am trying to learn django. I have gathered basic about this from their official site. I am now trying to read source codes of different projects available on github and trying to understand them. I am now trying to modify a project on github named ecommerce2, link . I'm trying to use MySQL database instead of SQlite as they did here. I installed mysql and changed the settings as instructed here . But one command here sudo mysql_install_db didn't work and said to be deprecated.

Now I'm having following error when I ran makemigrations and migrate command.

ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb

I'm on Ubuntu 16.04LTS

You need to install the PyMySQLdb module into your Python environment. Do pip install MySQL-python , and it should install the MySQL bindings in your Python environment.

You can install mysql db using pip install mysql-python command,if you want specific version of python mysql use pip install mysql-python==1.2.5

https://pypi.python.org/pypi/MySQL-python/1.2.5

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'django_api_test', # database name
'USER': 'root', # database username
'PASSWORD': 'admin', # database password
}

}

Do database setting in setting.py file. Thanks

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM