简体   繁体   English

如何将MySQL作为django项目的数据库使用?

[英]How to use MySQL as DB for a django project?

I am trying to learn django. 我正在尝试学习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. 我现在正在尝试阅读github上可用的不同项目的源代码,并试图理解它们。 I am now trying to modify a project on github named ecommerce2, link . 我现在正在尝试在github上修改一个名为ecommerce2, link的项目 I'm trying to use MySQL database instead of SQlite as they did here. 我正在尝试使用MySQL数据库而不是SQlite,就像他们在这里所做的那样。 I installed mysql and changed the settings as instructed here . 我安装了mysql并按照此处的说明更改了设置。 But one command here sudo mysql_install_db didn't work and said to be deprecated. 但是这里的一个命令sudo mysql_install_db不起作用,据说已被弃用。

Now I'm having following error when I ran makemigrations and migrate command. 现在,当我运行makemigrationsmigrate命令时,出现以下错误。

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 我在Ubuntu 16.04LTS上

You need to install the PyMySQLdb module into your Python environment. 您需要将PyMySQLdb模块安装到Python环境中。 Do pip install MySQL-python , and it should install the MySQL bindings in your Python environment. pip install MySQL-python ,它应该在您的Python环境中安装MySQL绑定。

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 您可以使用pip install mysql-python命令安装mysql db,如果要使用特定版本的python mysql,请使用pip install mysql-python == 1.2.5

https://pypi.python.org/pypi/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. 在setting.py文件中进行数据库设置。 Thanks 谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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