{"id":201066,"date":"2025-05-06T08:06:42","date_gmt":"2025-05-06T00:06:42","guid":{"rendered":"https:\/\/server.hk\/cnblog\/201066\/"},"modified":"2025-05-06T08:06:42","modified_gmt":"2025-05-06T00:06:42","slug":"django-%e9%a1%b9%e7%9b%ae%e8%bf%90%e8%a1%8c%e6%97%b6%e6%8a%a5%e9%94%99django-core-exceptions-improperlyconfigured-django-db-backends-mysql-isnt-an-available-database-backend","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/201066\/","title":{"rendered":"Django \u9879\u76ee\u8fd0\u884c\u65f6\u62a5\u9519\u201cdjango.core.exceptions.ImproperlyConfigured: &#8216;django.db.backends.mysql&#8217; isn&#8217;t an available database backend\u201d\uff0c\u5982\u4f55\u89e3\u51b3\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>Django \u9879\u76ee\u8fd0\u884c\u65f6\u62a5\u9519\u201cdjango.core.exceptions.ImproperlyConfigured: &#8216;django.db.backends.mysql&#8217; isn&#8217;t an available database backend\u201d\uff0c\u5982\u4f55\u89e3\u51b3\uff1f<\/h1>\n<p>\u672c\u7bc7\u6587\u7ae0\u5411\u5927\u5bb6\u4ecb\u7ecd\u300aDjango \u9879\u76ee\u8fd0\u884c\u65f6\u62a5\u9519\u201cdjango.core.exceptions.ImproperlyConfigured: &#8216;django.db.backends.mysql&#8217; isn&#8217;t an available database backend\u201d\uff0c\u5982\u4f55\u89e3\u51b3\uff1f\u300b\uff0c\u4e3b\u8981\u5305\u62ec\uff0c\u5177\u6709\u4e00\u5b9a\u7684\u53c2\u8003\u4ef7\u503c\uff0c\u9700\u8981\u7684\u670b\u53cb\u53ef\u4ee5\u53c2\u8003\u4e00\u4e0b\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241129\/17328467156749247b35c16.jpg\" class=\"aligncenter\"><\/p>\n<p><strong>\u8fd0\u884c django \u9879\u76ee\u65f6\u201cdjango.core.exceptions.improperlyconfigured\u201d\u9519\u8bef<\/strong><\/p>\n<p>\u9879\u76ee\u5728\u8fd0\u884c\u65f6\u51fa\u73b0\u4e86\u5982\u4e0b\u9519\u8bef\uff1a<\/p>\n<pre>django.core.exceptions.improperlyconfigured: 'django.db.backends.mysql' isn't an available database backend or couldn't be imported. check the above exception. to use one of the built-in backends, use 'django.db.backends.xxx', where xxx is one of:\n    'oracle', 'postgresql', 'sqlite3'<\/pre>\n<p><strong>\u9519\u8bef\u5206\u6790<\/strong><\/p>\n<p>\u6b64\u9519\u8bef\u8868\u660e django \u65e0\u6cd5\u627e\u5230\u6216\u5bfc\u5165 mysql \u6570\u636e\u5e93\u540e\u7aef\u6a21\u5757\u3002\u5728 python 3.8 \u4e2d\uff0c\u5185\u7f6e\u7684 mysql \u540e\u7aef\u9a71\u52a8\u5df2\u5220\u9664\u3002<\/p>\n<p><strong>\u89e3\u51b3\u65b9\u6848<\/strong><\/p>\n<p>\u8981\u89e3\u51b3\u6b64\u95ee\u9898\uff0c\u8bf7\u786e\u4fdd\u4ee5\u4e0b\u4e8b\u9879\uff1a<\/p>\n<ol>\n<li><strong>\u4f7f\u7528\u6b63\u786e\u7684 python \u7248\u672c<\/strong><\/li>\n<\/ol>\n<p>\u95ee\u9898\u4e2d\u63d0\u5230\u7684 django \u548c mysqlclient \u7248\u672c\u9002\u7528\u4e8e python 3.7\u3002\u8bf7\u68c0\u67e5\u4f60\u7684 python \u7248\u672c\u662f\u5426\u6b63\u786e\u3002<\/p>\n<ol>\n<li><strong>\u5b89\u88c5 mysql \u9a71\u52a8<\/strong><\/li>\n<\/ol>\n<p>\u5bf9\u4e8e python 3.8 \u53ca\u66f4\u9ad8\u7248\u672c\uff0c\u9700\u8981\u5b89\u88c5 mysql \u9a71\u52a8\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre>pip install mysql-connector-python<\/pre>\n<ol>\n<li><strong>\u4fee\u6539\u6570\u636e\u5e93\u914d\u7f6e<\/strong><\/li>\n<\/ol>\n<p>\u5728 settings.py \u4e2d\uff0c\u5c06\u6570\u636e\u5e93\u540e\u7aef\u66f4\u65b0\u4e3a &#8220;django.db.backends.mysql&#8221;:<\/p>\n<pre>databases = {\n    'default': {\n        'engine': 'django.db.backends.mysql',\n        # \u5176\u4ed6\u6570\u636e\u5e93\u914d\u7f6e...\n    }\n}<\/pre>\n<ol>\n<li><strong>\u91cd\u542f django \u670d\u52a1<\/strong><\/li>\n<\/ol>\n<p>\u5b89\u88c5 mysql \u9a71\u52a8\u540e\uff0c\u52a1\u5fc5\u91cd\u542f django \u670d\u52a1\u4ee5\u52a0\u8f7d\u65b0\u9a71\u52a8\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre>python manage.py runserver<\/pre>\n<p><strong>\u63d0\u793a\uff1a<\/strong><\/p>\n<p>\u5982\u679c\u5728\u5b89\u88c5 mysql-connector-python \u65f6\u9047\u5230\u95ee\u9898\uff0c\u8bf7\u786e\u4fdd\u5df2\u5b89\u88c5\u4ee5\u4e0b\u4f9d\u8d56\u9879\uff1a<\/p>\n<ul>\n<li>visual c++ redistributable<\/li>\n<li>mysql \u5f00\u53d1\u5e93 (\u7528\u4e8e linux\/macos)<\/li>\n<\/ul>\n<p>\u7ec8\u4e8e\u4ecb\u7ecd\u5b8c\u5566\uff01\u5c0f\u4f19\u4f34\u4eec\uff0c\u8fd9\u7bc7\u5173\u4e8e\u300aDjango \u9879\u76ee\u8fd0\u884c\u65f6\u62a5\u9519\u201cdjango.core.exceptions.ImproperlyConfigured: &#8216;django.db.backends.mysql&#8217; isn&#8217;t an available database backend\u201d\uff0c\u5982\u4f55\u89e3\u51b3\uff1f\u300b\u7684\u4ecb\u7ecd\u5e94\u8be5\u8ba9\u4f60\u6536\u83b7\u591a\u591a\u4e86\u5427\uff01\u6b22\u8fce\u5927\u5bb6\u6536\u85cf\u6216\u5206\u4eab\u7ed9\u66f4\u591a\u9700\u8981\u5b66\u4e60\u7684\u670b\u53cb\u5427~\u4e3b\u673a\u5b9d\u8d1d\u516c\u4f17\u53f7\u4e5f\u4f1a\u53d1\u5e03\u6570\u636e\u5e93\u76f8\u5173\u77e5\u8bc6\uff0c\u5feb\u6765\u5173\u6ce8\u5427\uff01<\/p>\n<dl>\n<dt>\n <\/dt>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>Django \u9879\u76ee\u8fd0\u884c\u65f6\u62a5\u9519\u201cd&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-201066","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/201066","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=201066"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/201066\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=201066"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=201066"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=201066"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}