{"id":7598,"date":"2024-11-14T11:14:11","date_gmt":"2024-11-14T03:14:11","guid":{"rendered":"https:\/\/fwq.ai\/blog\/7598\/"},"modified":"2024-11-14T11:14:11","modified_gmt":"2024-11-14T03:14:11","slug":"django-%e9%a1%b9%e7%9b%ae%e5%90%af%e5%8a%a8%e6%8a%a5%e9%94%99django-core-exceptions-improperlyconfigured%ef%bc%9a%e5%a6%82%e4%bd%95%e8%a7%a3%e5%86%b3mysql-%e6%95%b0%e6%8d%ae%e5%ba%93","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/7598\/","title":{"rendered":"Django \u9879\u76ee\u542f\u52a8\u62a5\u9519\u201cdjango.core.exceptions.ImproperlyConfigured\u201d\uff1a\u5982\u4f55\u89e3\u51b3MySQL \u6570\u636e\u5e93\u8fde\u63a5\u95ee\u9898\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173104778155727.jpg\" class=\"aligncenter\" title=\"Django \u9879\u76ee\u542f\u52a8\u62a5\u9519\u201cdjango.core.exceptions.ImproperlyConfigured\u201d\uff1a\u5982\u4f55\u89e3\u51b3MySQL \u6570\u636e\u5e93\u8fde\u63a5\u95ee\u9898\uff1f\u63d2\u56fe\" alt=\"Django \u9879\u76ee\u542f\u52a8\u62a5\u9519\u201cdjango.core.exceptions.ImproperlyConfigured\u201d\uff1a\u5982\u4f55\u89e3\u51b3MySQL \u6570\u636e\u5e93\u8fde\u63a5\u95ee\u9898\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u201cdjango.core.exceptions.improperlyconfigured\u201d\u9519\u8bef\uff1a\u89e3\u51b3\u65b9\u6848<\/strong><\/p>\n<p>\u5728\u5c1d\u8bd5\u8fd0\u884c django \u9879\u76ee\u65f6\uff0c\u4f60\u53ef\u80fd\u4f1a\u9047\u5230\u4ee5\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.<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u539f\u56e0<\/strong><\/p>\n<p>\u6b64\u9519\u8bef\u901a\u5e38\u662f\u56e0\u4e3a\u4ee5\u4e0b\u539f\u56e0\u800c\u53d1\u751f\u7684\uff1a<\/p>\n<ul>\n<li>django \u65e0\u6cd5\u5bfc\u5165  \u6570\u636e\u5e93\u540e\u7aef\u3002<\/li>\n<li>\u4f60\u5728 django \u7684 databases \u8bbe\u7f6e\u4e2d\u914d\u7f6e\u4e86 mysql \u4f46\u672a\u5b89\u88c5\u6b63\u786e\u7684\u540e\u7aef\u3002<\/li>\n<\/ul>\n<p><strong>\u89e3\u51b3\u65b9\u6848<\/strong><\/p>\n<p><strong>\u68c0\u67e5  \u7248\u672c<\/strong><\/p>\n<p>\u786e\u4fdd\u4f60\u786e\u5b9e\u4f7f\u7528\u7684\u662f python 3.7.4\uff0c\u800c\u4e0d\u662f 3.8.6\u3002<\/p>\n<p><strong>\u786e\u4fdd\u5b89\u88c5\u4e86\u9002\u5f53\u7684\u6570\u636e\u5e93\u540e\u7aef<\/strong><\/p>\n<p>\u5bf9\u4e8e django 3.2.19 \u548c mysql\uff0c\u5b89\u88c5 mysqlclient \u5305\uff1a<\/p>\n<pre>pip install mysqlclient<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u9a8c\u8bc1\u914d\u7f6e<\/strong><\/p>\n<p>\u68c0\u67e5\u4f60\u7684 django settings.py \u6587\u4ef6\u4e2d\u7684 databases \u8bbe\u7f6e\u662f\u5426\u6b63\u786e\u3002\u786e\u4fdd\u62e5\u6709\u4ee5\u4e0b\u5185\u5bb9\uff1a<\/p>\n<pre>DATABASES = {\n    'default': {\n        'ENGINE': 'django.db.backends.mysql',\n        'NAME': '\u4f60\u7684\u6570\u636e\u5e93\u540d\u79f0',\n        'USER': '\u4f60\u7684\u6570\u636e\u5e93\u7528\u6237',\n        'PASSWORD': '\u4f60\u7684\u6570\u636e\u5e93\u5bc6\u7801',\n        'HOST': '\u4f60\u7684\u6570\u636e\u5e93\u4e3b\u673a',\n        'PORT': '\u4f60\u7684\u6570\u636e\u5e93\u7aef\u53e3',\n    }\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u786e\u4fdd\u4f7f\u7528\u7684 engine \u503c\u4e3a django.db.backends.mysql\u3002<\/p>\n<p><strong>\u5176\u4ed6\u63d0\u793a<\/strong><\/p>\n<ul>\n<li>\u5c1d\u8bd5\u91cd\u65b0\u542f\u52a8 django \u9879\u76ee\u6216\u670d\u52a1\u5668\u3002<\/li>\n<li>\u786e\u4fdd\u4f60\u7684 mysql \u6570\u636e\u5e93\u6b63\u5728\u8fd0\u884c\u3002<\/li>\n<li>\u68c0\u67e5\u4f60\u7684 manage.py \u6587\u4ef6\u662f\u5426\u4e0e django \u7248\u672c\u517c\u5bb9\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662fDjango \u9879\u76ee\u542f\u52a8\u62a5\u9519\u201cdjango.core.exceptions.ImproperlyConfigured\u201d\uff1a\u5982\u4f55\u89e3\u51b3MySQL \u6570\u636e\u5e93\u8fde\u63a5\u95ee\u9898\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u7f51\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u201cdjango.core.exceptions.improperlyconfigured\u201d\u9519\u8bef\uff1a\u89e3\u51b3\u65b9\u6848 \u5728\u5c1d\u8bd5\u8fd0\u884c django \u9879\u76ee\u65f6\uff0c\u4f60\u53ef\u80fd\u4f1a\u9047\u5230\u4ee5\u4e0b\u9519\u8bef\uff1a django.core.exceptions.improperlyconfigured: &#8216;django.db.backends.mysql&#8217; isn&#8217;t an available database backend or couldn&#8217;t be imported. \u767b\u5f55\u540e\u590d\u5236 \u539f\u56e0 \u6b64\u9519\u8bef\u901a\u5e38\u662f\u56e0\u4e3a\u4ee5\u4e0b\u539f\u56e0\u800c\u53d1\u751f\u7684\uff1a django \u65e0\u6cd5\u5bfc\u5165 \u6570\u636e\u5e93\u540e\u7aef\u3002 \u4f60\u5728 django \u7684 databases \u8bbe\u7f6e\u4e2d\u914d\u7f6e\u4e86 mysql \u4f46\u672a\u5b89\u88c5\u6b63\u786e\u7684\u540e\u7aef\u3002 \u89e3\u51b3\u65b9\u6848 \u68c0\u67e5 \u7248\u672c \u786e\u4fdd\u4f60\u786e\u5b9e\u4f7f\u7528\u7684\u662f python 3.7.4\uff0c\u800c\u4e0d\u662f 3.8.6\u3002 \u786e\u4fdd\u5b89\u88c5\u4e86\u9002\u5f53\u7684\u6570\u636e\u5e93\u540e\u7aef \u5bf9\u4e8e django 3.2.19 \u548c mysql\uff0c\u5b89\u88c5 mysqlclient \u5305\uff1a pip install mysqlclient \u767b\u5f55\u540e\u590d\u5236 \u9a8c\u8bc1\u914d\u7f6e \u68c0\u67e5\u4f60\u7684 django settings.py \u6587\u4ef6\u4e2d\u7684 databases \u8bbe\u7f6e\u662f\u5426\u6b63\u786e\u3002\u786e\u4fdd\u62e5\u6709\u4ee5\u4e0b\u5185\u5bb9\uff1a DATABASES [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-7598","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/7598","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=7598"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/7598\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=7598"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=7598"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=7598"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}