我已经安装了mysql connector
,它已经具有内置的sql适配器,我也不需要安装mysqlclient
,因为我有mysql连接器。但是当我开始python manage.py migration时,它要求我下载mysqlclient。但是我无法安装mysqlclient
。谁能帮我解决问题。谢谢
错误:
File "C:\Program Files (x86)\Python37-32\lib\site-packages\django\db\models\base.py", line 101, in __new__
new_class.add_to_class('_meta', Options(meta, app_label))
File "C:\Program Files (x86)\Python37-32\lib\site-packages\django\db\models\base.py", line 305, in add_to_class
value.contribute_to_class(cls, name)
File "C:\Program Files (x86)\Python37-32\lib\site-packages\django\db\models\options.py", line 203, in contribute_to_class
self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
File "C:\Program Files (x86)\Python37-32\lib\site-packages\django\db\__init__.py", line 33, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "C:\Program Files (x86)\Python37-32\lib\site-packages\django\db\utils.py", line 202, in __getitem__
backend = load_backend(db['ENGINE'])
File "C:\Program Files (x86)\Python37-32\lib\site-packages\django\db\utils.py", line 110, in load_backend
return import_module('%s.base' % backend_name)
File "C:\Program Files (x86)\Python37-32\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "C:\Program Files (x86)\Python37-32\lib\site-packages\django\db\backends\mysql\base.py", line 20, in <module>
) from err
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module.
Did you install mysqlclient?
答案 0 :(得分:1)
也许您需要在以下位置安装mysql-connector-c连接器:
pip install mysqlclient==1.3.13
答案 1 :(得分:0)
There are two backends用于将MySQL与python配合使用
首先,您需要确定要使用哪个后端。
如果要使用mysql连接器,则无需安装mysqlclient
。您确实需要在ENGINES
设置中更改DATABASES
才能使用连接器后端。
DATABASES = {
'default': {
'NAME': 'user_data',
'ENGINE': 'mysql.connector.django',
...
},
...
}
如果进行此更改,它将停止您安装mysqlclient 错误消息。有关使用mysql连接器的更多信息,请参见the docs。
如果要使用mysqlclient
,请在'django.db.backends.mysql'
设置中将ENGINE保留为DATABASES
。在Windows上安装mysqlclient
可能很棘手,您有几种选择:
安装官方轮子。截至2018年12月,有适用于Python 3.6和Python 3.7的最新版本mysqlclient 1.3.14的轮子。使用以下命令安装mysqlclient:
pip install mysqlclient==1.3.14