{"id":61201,"date":"2024-10-13T09:16:17","date_gmt":"2024-10-13T01:16:17","guid":{"rendered":"https:\/\/server.hk\/cnblog\/61201\/"},"modified":"2024-10-13T09:16:17","modified_gmt":"2024-10-13T01:16:17","slug":"django%e6%94%af%e6%8c%81%e7%9a%84%e6%95%b8%e6%93%9a%e5%ba%ab%e4%b8%80%e8%a6%bd-django-%e6%94%af%e6%8c%81%e7%9a%84%e6%95%b8%e6%93%9a%e5%ba%ab","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/61201\/","title":{"rendered":"Django\u652f\u6301\u7684\u6578\u64da\u5eab\u4e00\u89bd (django \u652f\u6301\u7684\u6578\u64da\u5eab)"},"content":{"rendered":"<h1 id=\"django%e6%94%af%e6%8c%81%e7%9a%84%e6%95%b8%e6%93%9a%e5%ba%ab%e4%b8%80%e8%a6%bd-QazlDbyQPK\">Django\u652f\u6301\u7684\u6578\u64da\u5eab\u4e00\u89bd<\/h1>\n<p>Django\u662f\u4e00\u500b\u9ad8\u6548\u7684Python\u7db2\u9801\u6846\u67b6\uff0c\u5ee3\u6cdb\u61c9\u7528\u65bc\u958b\u767c\u5404\u985e\u578b\u7684\u7db2\u7ad9\u548c\u61c9\u7528\u7a0b\u5f0f\u3002\u5176\u5f37\u5927\u7684ORM\uff08\u5c0d\u8c61\u95dc\u806f\u6620\u5c04\uff09\u7cfb\u7d71\u4f7f\u5f97\u958b\u767c\u8005\u80fd\u5920\u8f15\u9b06\u5730\u8207\u6578\u64da\u5eab\u9032\u884c\u4ea4\u4e92\u3002\u672c\u6587\u5c07\u4ecb\u7d39Django\u652f\u6301\u7684\u4e3b\u8981\u6578\u64da\u5eab\uff0c\u5e6b\u52a9\u958b\u767c\u8005\u9078\u64c7\u6700\u9069\u5408\u5176\u9805\u76ee\u7684\u6578\u64da\u5eab\u89e3\u6c7a\u65b9\u6848\u3002<\/p>\n<h2 id=\"1-sqlite-QazlDbyQPK\">1. SQLite<\/h2>\n<p>SQLite\u662fDjango\u7684\u9ed8\u8a8d\u6578\u64da\u5eab\uff0c\u9069\u5408\u5c0f\u578b\u61c9\u7528\u548c\u958b\u767c\u968e\u6bb5\u7684\u6e2c\u8a66\u3002\u5b83\u662f\u4e00\u500b\u8f15\u91cf\u7d1a\u7684\u6578\u64da\u5eab\uff0c\u7121\u9700\u5b89\u88dd\u548c\u914d\u7f6e\uff0c\u6240\u6709\u6578\u64da\u90fd\u5b58\u5132\u5728\u4e00\u500b\u6587\u4ef6\u4e2d\u3002\u9019\u4f7f\u5f97SQLite\u975e\u5e38\u65b9\u4fbf\uff0c\u7279\u5225\u662f\u5728\u958b\u767c\u548c\u6e2c\u8a66\u74b0\u5883\u4e2d\u3002<\/p>\n<pre><code>DATABASES = {\n    'default': {\n        'ENGINE': 'django.db.backends.sqlite3',\n        'NAME': BASE_DIR \/ \"db.sqlite3\",\n    }\n}<\/code><\/pre>\n<h2 id=\"2-postgresql-QazlDbyQPK\">2. PostgreSQL<\/h2>\n<p>PostgreSQL\u662f\u4e00\u500b\u529f\u80fd\u5f37\u5927\u7684\u958b\u6e90\u95dc\u806f\u6578\u64da\u5eab\uff0c\u652f\u6301\u8907\u96dc\u7684\u67e5\u8a62\u548c\u6578\u64da\u985e\u578b\u3002Django\u5c0dPostgreSQL\u7684\u652f\u6301\u975e\u5e38\u597d\uff0c\u63d0\u4f9b\u4e86\u8a31\u591a\u7279\u6027\uff0c\u5982JSON\u5b57\u6bb5\u3001\u5168\u6587\u641c\u7d22\u7b49\u3002\u9019\u4f7f\u5f97PostgreSQL\u6210\u70ba\u4e2d\u5927\u578b\u61c9\u7528\u7684\u7406\u60f3\u9078\u64c7\u3002<\/p>\n<pre><code>DATABASES = {\n    'default': {\n        'ENGINE': 'django.db.backends.postgresql',\n        'NAME': 'mydatabase',\n        'USER': 'myuser',\n        'PASSWORD': 'mypassword',\n        'HOST': 'localhost',\n        'PORT': '5432',\n    }\n}<\/code><\/pre>\n<h2 id=\"3-mysql-QazlDbyQPK\">3. MySQL<\/h2>\n<p>MySQL\u662f\u53e6\u4e00\u500b\u6d41\u884c\u7684\u958b\u6e90\u6578\u64da\u5eab\uff0c\u5ee3\u6cdb\u61c9\u7528\u65bc\u5404\u7a2e\u7db2\u7ad9\u548c\u61c9\u7528\u3002Django\u652f\u6301MySQL\uff0c\u4e26\u63d0\u4f9b\u4e86\u826f\u597d\u7684\u6027\u80fd\u548c\u7a69\u5b9a\u6027\u3002MySQL\u9069\u5408\u9700\u8981\u9ad8\u4e26\u767c\u548c\u5feb\u901f\u67e5\u8a62\u7684\u61c9\u7528\u3002<\/p>\n<pre><code>DATABASES = {\n    'default': {\n        'ENGINE': 'django.db.backends.mysql',\n        'NAME': 'mydatabase',\n        'USER': 'myuser',\n        'PASSWORD': 'mypassword',\n        'HOST': 'localhost',\n        'PORT': '3306',\n    }\n}<\/code><\/pre>\n<h2 id=\"4-mariadb-QazlDbyQPK\">4. MariaDB<\/h2>\n<p>MariaDB\u662fMySQL\u7684\u4e00\u500b\u5206\u652f\uff0c\u65e8\u5728\u63d0\u4f9b\u66f4\u597d\u7684\u6027\u80fd\u548c\u5b89\u5168\u6027\u3002Django\u540c\u6a23\u652f\u6301MariaDB\uff0c\u4e26\u4e14\u8a31\u591aMySQL\u7684\u529f\u80fd\u5728MariaDB\u4e2d\u4e5f\u80fd\u5920\u4f7f\u7528\u3002\u5c0d\u65bc\u5e0c\u671b\u4f7f\u7528MySQL\u4f46\u53c8\u60f3\u8981\u66f4\u9ad8\u6027\u80fd\u7684\u958b\u767c\u8005\u4f86\u8aaa\uff0cMariaDB\u662f\u4e00\u500b\u4e0d\u932f\u7684\u9078\u64c7\u3002<\/p>\n<pre><code>DATABASES = {\n    'default': {\n        'ENGINE': 'django.db.backends.mysql',\n        'NAME': 'mydatabase',\n        'USER': 'myuser',\n        'PASSWORD': 'mypassword',\n        'HOST': 'localhost',\n        'PORT': '3306',\n    }\n}<\/code><\/pre>\n<h2 id=\"5-oracle-QazlDbyQPK\">5. Oracle<\/h2>\n<p>Oracle\u6578\u64da\u5eab\u662f\u4e00\u500b\u5546\u696d\u7d1a\u7684\u95dc\u806f\u6578\u64da\u5eab\uff0c\u9069\u5408\u5927\u578b\u4f01\u696d\u61c9\u7528\u3002Django\u5c0dOracle\u7684\u652f\u6301\u4f7f\u5f97\u958b\u767c\u8005\u80fd\u5920\u5229\u7528\u5176\u5f37\u5927\u7684\u529f\u80fd\uff0c\u5982\u9ad8\u53ef\u7528\u6027\u548c\u5b89\u5168\u6027\u3002\u96d6\u7136Oracle\u7684\u4f7f\u7528\u6210\u672c\u8f03\u9ad8\uff0c\u4f46\u5c0d\u65bc\u9700\u8981\u9ad8\u6027\u80fd\u548c\u7a69\u5b9a\u6027\u7684\u4f01\u696d\u4f86\u8aaa\uff0c\u9019\u662f\u4e00\u500b\u503c\u5f97\u8003\u616e\u7684\u9078\u64c7\u3002<\/p>\n<pre><code>DATABASES = {\n    'default': {\n        'ENGINE': 'django.db.backends.oracle',\n        'NAME': 'mydatabase',\n        'USER': 'myuser',\n        'PASSWORD': 'mypassword',\n        'HOST': 'localhost',\n        'PORT': '1521',\n    }\n}<\/code><\/pre>\n<h2 id=\"6-microsoft-sql-server-QazlDbyQPK\">6. Microsoft SQL Server<\/h2>\n<p>Django\u4e5f\u652f\u6301Microsoft SQL Server\uff0c\u9019\u5c0d\u65bc\u4f7f\u7528Windows\u74b0\u5883\u7684\u958b\u767c\u8005\u4f86\u8aaa\u975e\u5e38\u65b9\u4fbf\u3002SQL Server\u63d0\u4f9b\u4e86\u5f37\u5927\u7684\u6578\u64da\u8655\u7406\u80fd\u529b\uff0c\u9069\u5408\u9700\u8981\u9ad8\u6027\u80fd\u7684\u5546\u696d\u61c9\u7528\u3002<\/p>\n<pre><code>DATABASES = {\n    'default': {\n        'ENGINE': 'sql_server.pyodbc',\n        'NAME': 'mydatabase',\n        'USER': 'myuser',\n        'PASSWORD': 'mypassword',\n        'HOST': 'localhost',\n        'PORT': '1433',\n        'OPTIONS': {\n            'driver': 'ODBC Driver 17 for SQL Server',\n        },\n    }\n}<\/code><\/pre>\n<h2 id=\"%e7%b8%bd%e7%b5%90-QazlDbyQPK\">\u7e3d\u7d50<\/h2>\n<p>Django\u652f\u6301\u591a\u7a2e\u6578\u64da\u5eab\uff0c\u5305\u62ecSQLite\u3001PostgreSQL\u3001MySQL\u3001MariaDB\u3001Oracle\u548cMicrosoft SQL Server\u3002\u6bcf\u7a2e\u6578\u64da\u5eab\u90fd\u6709\u5176\u7279\u9ede\u548c\u9069\u7528\u5834\u666f\uff0c\u958b\u767c\u8005\u53ef\u4ee5\u6839\u64da\u9805\u76ee\u7684\u9700\u6c42\u9078\u64c7\u5408\u9069\u7684\u6578\u64da\u5eab\u89e3\u6c7a\u65b9\u6848\u3002\u7121\u8ad6\u662f\u5c0f\u578b\u61c9\u7528\u9084\u662f\u5927\u578b\u4f01\u696d\u7cfb\u7d71\uff0cDjango\u90fd\u80fd\u63d0\u4f9b\u9748\u6d3b\u7684\u6578\u64da\u5eab\u652f\u6301\u3002<\/p>\n<p>\u5982\u679c\u60a8\u6b63\u5728\u5c0b\u627e\u9ad8\u6548\u7684 <a href=\"https:\/\/server.hk\">VPS<\/a> \u89e3\u6c7a\u65b9\u6848\u4f86\u90e8\u7f72\u60a8\u7684Django\u61c9\u7528\uff0cServer.HK\u63d0\u4f9b\u591a\u7a2e\u9078\u64c7\uff0c\u6eff\u8db3\u4e0d\u540c\u9700\u6c42\u7684\u5ba2\u6236\u3002\u7121\u8ad6\u662f <a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a> \u9084\u662f\u5176\u4ed6\u985e\u578b\u7684 <a href=\"https:\/\/server.hk\">\u4f3a\u670d\u5668<\/a>\uff0c\u6211\u5011\u90fd\u80fd\u70ba\u60a8\u63d0\u4f9b\u7a69\u5b9a\u7684\u670d\u52d9\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u63a2\u7d22Django\u652f\u6301\u7684\u6578\u64da\u5eab\uff0c\u5305\u62ecPostgreSQL\u3001MySQL\u3001SQLite\u7b49\uff0c\u4e86\u89e3\u5982\u4f55\u9078\u64c7\u9069\u5408\u60a8\u9805\u76ee\u7684\u6578\u64da\u5eab\u89e3\u6c7a\u65b9\u6848\u3002<\/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-61201","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/61201","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=61201"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/61201\/revisions"}],"predecessor-version":[{"id":61202,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/61201\/revisions\/61202"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=61201"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=61201"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=61201"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}