gpt4 book ai didi

mysql - 无法使用 MySQL 后端运行 Django

转载 作者:行者123 更新时间:2023-11-29 00:32:21 25 4
gpt4 key购买 nike

我正在尝试使用 MySQL 后端设置 Django,之前我只使用过 sqlite,但我遇到了一个相当奇怪的错误。 错误是:没有名为 mysql.base 的模块

我正在运行带有 Nginx 和 uwsgi 的 Ubuntu,并且安装了 python-mysqldb。在此之后,我开始收到 502,所以我希望这是相关的,因为我没有更改任何配置文件。

这是 manage.py inspectdb 之后的堆栈跟踪;

Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 453, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 272, in fetch_command
klass = load_command_class(app_name, subcommand)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 77, in load_command_class
module = import_module('%s.management.commands.%s' % (app_name, name))
File "/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/inspectdb.py", line 8, in <module>
from django.db import connections, DEFAULT_DB_ALIAS
File "/usr/local/lib/python2.7/dist-packages/django/db/__init__.py", line 40, in <module>
backend = load_backend(connection.settings_dict['ENGINE'])
File "/usr/local/lib/python2.7/dist-packages/django/db/__init__.py", line 34, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "/usr/local/lib/python2.7/dist-packages/django/db/utils.py", line 93, in __getitem__
backend = load_backend(db['ENGINE'])
File "/usr/local/lib/python2.7/dist-packages/django/db/utils.py", line 45, in load_backend
raise ImproperlyConfigured(error_msg)
django.core.exceptions.ImproperlyConfigured: 'django.db.backends.mysql' isn't an available database backend.
Try using 'django.db.backends.XXX', where XXX is one of:
u'oracle', u'postgresql_psycopg2', u'sqlite3'
Error was: No module named mysql.base

数据库设置;

  DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'wdsdj', # Or path to database file if using sqlite3
# The following settings are not used with sqlite3:
'USER': 'mark',
'PASSWORD': 'pass',
'HOST': '', # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP.
'PORT': '', # Set to empty string for default.
}
}

如果我更改为 sqlite3,那么 dj 不会有任何问题;

# This is an auto-generated Django model module.
# You'll have to do the following manually to clean this up:
# * Rearrange models' order
# * Make sure each model has one field with primary_key=True
# Feel free to rename the models, but don't rename db_table values or field names.
#
# Also note: You'll have to insert the output of 'django-admin.py sqlcustom [appname]'
# into your database.
from __future__ import unicode_literals

from django.db import models

最佳答案

检查您的设置,确保 ENGINE 是正确的 django.db.backends.mysql

然后确保你已经安装了python-mysqldb...

sudo apt-get install python-mysqldb

但是,在您的错误堆栈中它指出“不是可用的数据库后端”,这似乎是您的 Django 安装出了问题,对吗?

关于mysql - 无法使用 MySQL 后端运行 Django,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15955932/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com