{"id":6720,"date":"2024-11-14T08:43:36","date_gmt":"2024-11-14T00:43:36","guid":{"rendered":"https:\/\/fwq.ai\/blog\/6720\/"},"modified":"2024-11-14T08:43:36","modified_gmt":"2024-11-14T00:43:36","slug":"sequelize-%e9%bb%98%e8%ae%a4%e6%97%b6%e9%97%b4%e7%94%9f%e6%88%90%e4%b8%8d%e5%87%86%ef%bc%8c%e5%a6%82%e4%bd%95%e8%a7%a3%e5%86%b3%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/6720\/","title":{"rendered":"Sequelize \u9ed8\u8ba4\u65f6\u95f4\u751f\u6210\u4e0d\u51c6\uff0c\u5982\u4f55\u89e3\u51b3\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/172982147873246.jpg\" class=\"aligncenter\" title=\"Sequelize \u9ed8\u8ba4\u65f6\u95f4\u751f\u6210\u4e0d\u51c6\uff0c\u5982\u4f55\u89e3\u51b3\uff1f\u63d2\u56fe\" alt=\"Sequelize \u9ed8\u8ba4\u65f6\u95f4\u751f\u6210\u4e0d\u51c6\uff0c\u5982\u4f55\u89e3\u51b3\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>sequelize \u9ed8\u8ba4\u65f6\u95f4\u751f\u6210\u4e0d\u51c6\u7684\u539f\u56e0\u548c\u89e3\u51b3\u529e\u6cd5<\/strong><\/p>\n<p>\u5728\u4f7f\u7528 sequelize orm \u6846\u67b6\u4e0e  \u6570\u636e\u5e93\u4ea4\u4e92\u65f6\uff0c\u6211\u4eec\u53ef\u80fd\u4f1a\u9047\u5230\u8fd9\u6837\u4e00\u4e2a\u95ee\u9898\uff1asequelize \u751f\u6210\u7684\u9ed8\u8ba4\u65f6\u95f4\u6233\u5b57\u6bb5\uff08\u5982 createdat \u548c updatedat) \u4e0e\u5b9e\u9645\u65f6\u95f4\u4e0d\u4e00\u81f4\uff0c\u76f8\u5dee 10 \u591a\u4e2a\u5c0f\u65f6\u3002<\/p>\n<p><strong>\u95ee\u9898\u6839\u6e90<\/strong><\/p>\n<p>\u8fd9\u4e2a\u95ee\u9898\u7684\u6839\u6e90\u5728\u4e8e sequelize \u7684\u9ed8\u8ba4\u65f6\u533a\u8bbe\u7f6e\u3002sequelize \u4f7f\u7528 utc\uff08\u534f\u8c03\u7528\u65f6\uff09\u4f5c\u4e3a\u5176\u9ed8\u8ba4\u65f6\u533a\uff0c\u800c mysql \u4f7f\u7528\u672c\u5730\u65f6\u533a\u3002\u56e0\u6b64\uff0c\u5f53 sequelize \u751f\u6210\u65f6\u95f4\u6233\u65f6\uff0c\u5b83\u4f1a\u4f7f\u7528 utc \u65f6\u95f4\uff0c\u800c mysql \u5c06\u5176\u8f6c\u6362\u4e3a\u672c\u5730\u65f6\u533a\uff0c\u4ece\u800c\u5bfc\u81f4\u65f6\u95f4\u4e0d\u4e00\u81f4\u3002<\/p>\n<p><strong>\u89e3\u51b3\u65b9\u6848<\/strong><\/p>\n<p>\u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u9700\u8981\u8c03\u6574 sequelize \u7684\u65f6\u533a\u8bbe\u7f6e\uff0c\u4ee5\u5339\u914d mysql \u7684\u672c\u5730\u65f6\u533a\u3002\u4e3a\u6b64\uff0c\u9700\u8981\u5728 sequelize \u521d\u59cb\u5316\u65f6\u6307\u5b9a timezone \u548c useutc \u9009\u9879\u3002<\/p>\n<p>\u4fee\u6539\u540e\u7684\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre>const sequelize = new Sequelize('database', 'username', 'password', {\n  host: 'localhost',\n  dialect: 'mssql',\n  timezone: '+8:00', \/\/ \u6839\u636e\u5b9e\u9645\u65f6\u533a\u8c03\u6574\n  dialectOptions: {\n    useUTC: false\n  }\n});<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u901a\u8fc7\u6307\u5b9a timezone: &#8216;+8:00&#8217;\uff0c\u6211\u4eec\u5c06 sequelize \u7684\u65f6\u533a\u8bbe\u7f6e\u4e3a\u4e1c\u516b\u533a\u3002\u540c\u65f6\uff0c\u5c06 useutc \u8bbe\u7f6e\u4e3a false\uff0c\u7981\u7528 sequelize \u4f7f\u7528 utc \u65f6\u95f4\u3002\u8fd9\u6837\uff0csequelize \u751f\u6210\u7684\u9ed8\u8ba4\u65f6\u95f4\u6233\u5c06\u4e0e mysql \u7684\u672c\u5730\u65f6\u95f4\u4e00\u81f4\uff0c\u4ece\u800c\u89e3\u51b3\u65f6\u95f4\u4e0d\u51c6\u7684\u95ee\u9898\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fSequelize \u9ed8\u8ba4\u65f6\u95f4\u751f\u6210\u4e0d\u51c6\uff0c\u5982\u4f55\u89e3\u51b3\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>sequelize \u9ed8\u8ba4\u65f6\u95f4\u751f\u6210\u4e0d\u51c6\u7684\u539f\u56e0\u548c\u89e3\u51b3\u529e\u6cd5 \u5728\u4f7f\u7528 sequelize orm \u6846\u67b6\u4e0e \u6570\u636e\u5e93\u4ea4\u4e92\u65f6\uff0c\u6211\u4eec\u53ef\u80fd\u4f1a\u9047\u5230\u8fd9\u6837\u4e00\u4e2a\u95ee\u9898\uff1asequelize \u751f\u6210\u7684\u9ed8\u8ba4\u65f6\u95f4\u6233\u5b57\u6bb5\uff08\u5982 createdat \u548c updatedat) \u4e0e\u5b9e\u9645\u65f6\u95f4\u4e0d\u4e00\u81f4\uff0c\u76f8\u5dee 10 \u591a\u4e2a\u5c0f\u65f6\u3002 \u95ee\u9898\u6839\u6e90 \u8fd9\u4e2a\u95ee\u9898\u7684\u6839\u6e90\u5728\u4e8e sequelize \u7684\u9ed8\u8ba4\u65f6\u533a\u8bbe\u7f6e\u3002sequelize \u4f7f\u7528 utc\uff08\u534f\u8c03\u7528\u65f6\uff09\u4f5c\u4e3a\u5176\u9ed8\u8ba4\u65f6\u533a\uff0c\u800c mysql \u4f7f\u7528\u672c\u5730\u65f6\u533a\u3002\u56e0\u6b64\uff0c\u5f53 sequelize \u751f\u6210\u65f6\u95f4\u6233\u65f6\uff0c\u5b83\u4f1a\u4f7f\u7528 utc \u65f6\u95f4\uff0c\u800c mysql \u5c06\u5176\u8f6c\u6362\u4e3a\u672c\u5730\u65f6\u533a\uff0c\u4ece\u800c\u5bfc\u81f4\u65f6\u95f4\u4e0d\u4e00\u81f4\u3002 \u89e3\u51b3\u65b9\u6848 \u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u9700\u8981\u8c03\u6574 sequelize \u7684\u65f6\u533a\u8bbe\u7f6e\uff0c\u4ee5\u5339\u914d mysql \u7684\u672c\u5730\u65f6\u533a\u3002\u4e3a\u6b64\uff0c\u9700\u8981\u5728 sequelize \u521d\u59cb\u5316\u65f6\u6307\u5b9a timezone \u548c useutc \u9009\u9879\u3002 \u4fee\u6539\u540e\u7684\u4ee3\u7801\u5982\u4e0b\uff1a const sequelize = new Sequelize(&#8216;database&#8217;, &#8216;username&#8217;, &#8216;password&#8217;, { host: &#8216;localhost&#8217;, dialect: &#8216;mssql&#8217;, timezone: &#8216;+8:00&#8217;, [&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-6720","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6720","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=6720"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6720\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=6720"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=6720"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=6720"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}