{"id":21406,"date":"2024-01-02T08:51:25","date_gmt":"2024-01-02T08:51:25","guid":{"rendered":"https:\/\/server.hk\/blog\/21406\/"},"modified":"2024-11-14T10:35:01","modified_gmt":"2024-11-14T02:35:01","slug":"how-to-fix-postgresql-error-code-42804-datatype_mismatch","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/21406\/","title":{"rendered":"\u5982\u4f55\u4fee\u5fa9 PostgreSQL \u932f\u8aa4\u4ee3\u78bc\uff1a42804 &#8211; datatype_mismatch"},"content":{"rendered":"<h1>\u5982\u4f55\u4fee\u5fa9 PostgreSQL \u932f\u8aa4\u4ee3\u78bc\uff1a42804 &#8211; datatype_mismatch<\/h1>\n<p>PostgreSQL \u662f\u4e00\u500b\u529f\u80fd\u5f37\u5927\u7684\u958b\u6e90\u95dc\u4fc2\u578b\u6578\u64da\u5eab\u7ba1\u7406\u7cfb\u7d71\uff0c\u5ee3\u6cdb\u7528\u65bc\u5404\u7a2e\u61c9\u7528\u3002\u7136\u800c\uff0c\u50cf\u6240\u6709\u8edf\u4ef6\u4e00\u6a23\uff0c\u5b83\u53ef\u80fd\u6703\u9047\u5230\u6703\u5e72\u64fe\u6b63\u5e38\u904b\u4f5c\u7684\u932f\u8aa4\u3002\u5176\u4e2d\u4e00\u500b\u932f\u8aa4\u662f PostgreSQL \u932f\u8aa4\u4ee3\u78bc\uff1a42804 &#8211; datatype_mismatch\u3002\u5728\u672c\u6587\u4e2d\uff0c\u6211\u5011\u5c07\u63a2\u8a0e\u8a72\u932f\u8aa4\u7684\u539f\u56e0\u4e26\u63d0\u4f9b\u89e3\u6c7a\u65b9\u6848\u3002<\/p>\n<h2>\u7406\u89e3\u932f\u8aa4<\/h2>\n<p>PostgreSQL \u932f\u8aa4\u4ee3\u78bc\uff1a42804 &#8211; datatype_mismatch \u767c\u751f\u5728\u5217\u7684\u6578\u64da\u985e\u578b\u8207\u88ab\u63d2\u5165\u6216\u66f4\u65b0\u7684\u503c\u4e4b\u9593\u4e0d\u5339\u914d\u6642\u3002\u9019\u500b\u932f\u8aa4\u901a\u5e38\u5728\u57f7\u884c INSERT\u3001UPDATE \u6216 COPY \u7b49\u64cd\u4f5c\u6642\u51fa\u73fe\u3002<\/p>\n<p>\u4f8b\u5982\uff0c\u5047\u8a2d\u60a8\u6709\u4e00\u500b\u5b9a\u7fa9\u70ba\u6574\u6578\u7684\u5217\uff0c\u800c\u60a8\u5617\u8a66\u5c07\u5b57\u7b26\u4e32\u503c\u63d2\u5165\u8a72\u5217\u3002\u9019\u5c07\u89f8\u767c datatype_mismatch \u932f\u8aa4\u3002<\/p>\n<h2>\u932f\u8aa4\u539f\u56e0<\/h2>\n<p>\u60a8\u53ef\u80fd\u6703\u9047\u5230 datatype_mismatch \u932f\u8aa4\u7684\u539f\u56e0\u6709\u5e7e\u500b\uff1a<\/p>\n<ul>\n<li><strong>\u6578\u64da\u985e\u578b\u4e0d\u6b63\u78ba\uff1a<\/strong>\u6700\u5e38\u898b\u7684\u539f\u56e0\u662f\u5617\u8a66\u63d2\u5165\u6216\u66f4\u65b0\u8207\u5217\u9810\u671f\u7684\u6578\u64da\u985e\u578b\u4e0d\u540c\u7684\u503c\u3002<\/li>\n<li><strong>\u7f3a\u5c11\u6216\u7121\u6548\u503c\uff1a<\/strong>\u5982\u679c\u4e00\u500b\u5217\u6709 NOT NULL \u7d04\u675f\uff0c\u5247\u5fc5\u9808\u63d0\u4f9b\u4e00\u500b\u503c\u3002\u672a\u80fd\u63d0\u4f9b\u503c\u5c07\u5c0e\u81f4 datatype_mismatch \u932f\u8aa4\u3002<\/li>\n<li><strong>\u96b1\u5f0f\u985e\u578b\u8f49\u63db\uff1a<\/strong>PostgreSQL \u5728\u67d0\u4e9b\u60c5\u6cc1\u4e0b\u57f7\u884c\u96b1\u5f0f\u985e\u578b\u8f49\u63db\u3002\u5982\u679c\u8f49\u63db\u5931\u6557\uff0c\u5247\u6703\u5f15\u767c\u932f\u8aa4\u3002<\/li>\n<\/ul>\n<h2>\u4fee\u5fa9\u932f\u8aa4<\/h2>\n<p>\u8981\u89e3\u6c7a PostgreSQL \u932f\u8aa4\u4ee3\u78bc\uff1a42804 &#8211; datatype_mismatch\uff0c\u60a8\u53ef\u4ee5\u6309\u7167\u4ee5\u4e0b\u6b65\u9a5f\u64cd\u4f5c\uff1a<\/p>\n<h3>1. \u9a57\u8b49\u6578\u64da\u985e\u578b<\/h3>\n<p>\u4ed4\u7d30\u6aa2\u67e5\u53c3\u8207\u64cd\u4f5c\u7684\u5217\u7684\u6578\u64da\u985e\u578b\u3002\u78ba\u4fdd\u60a8\u6b63\u5728\u63d2\u5165\u6216\u66f4\u65b0\u7684\u503c\u8207\u9810\u671f\u7684\u6578\u64da\u985e\u578b\u76f8\u7b26\u3002\u5982\u6709\u5fc5\u8981\uff0c\u4fee\u6539\u5217\u7684\u6578\u64da\u985e\u578b\u4ee5\u8207\u60a8\u7684\u6578\u64da\u4fdd\u6301\u4e00\u81f4\u3002<\/p>\n<h3>2. \u63d0\u4f9b\u6709\u6548\u503c<\/h3>\n<p>\u5982\u679c\u4e00\u500b\u5217\u6709 NOT NULL \u7d04\u675f\uff0c\u8acb\u78ba\u4fdd\u5728\u64cd\u4f5c\u904e\u7a0b\u4e2d\u70ba\u8a72\u5217\u63d0\u4f9b\u6709\u6548\u503c\u3002\u5982\u679c\u60a8\u6c92\u6709\u53ef\u63d2\u5165\u7684\u503c\uff0c\u8003\u616e\u66f4\u6539\u8868\u4ee5\u5141\u8a31 NULL \u503c\u6216\u63d0\u4f9b\u9ed8\u8a8d\u503c\u3002<\/p>\n<h3>3. \u4f7f\u7528\u660e\u78ba\u7684\u985e\u578b\u8f49\u63db<\/h3>\n<p>\u5982\u679c\u9700\u8981\u57f7\u884c\u6d89\u53ca\u4e0d\u540c\u6578\u64da\u985e\u578b\u7684\u64cd\u4f5c\uff0c\u8acb\u4f7f\u7528\u660e\u78ba\u7684\u985e\u578b\u8f49\u63db\u51fd\u6578\u4ee5\u78ba\u4fdd\u517c\u5bb9\u6027\u3002\u4f8b\u5982\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528 <code>CAST<\/code> \u51fd\u6578\u5c07\u5b57\u7b26\u4e32\u8f49\u63db\u70ba\u6574\u6578\uff0c\u7136\u5f8c\u518d\u63d2\u5165\u6574\u6578\u5217\u4e2d\u3002<\/p>\n<h3>4. \u6aa2\u67e5\u96b1\u5f0f\u985e\u578b\u8f49\u63db<\/h3>\n<p>\u5982\u679c\u60a8\u61f7\u7591\u96b1\u5f0f\u985e\u578b\u8f49\u63db\u5c0e\u81f4\u932f\u8aa4\uff0c\u8acb\u6aa2\u67e5\u60a8\u7684\u67e5\u8a62\u548c\u8868\u9054\u5f0f\u3002\u78ba\u4fdd\u64cd\u4f5c\u4e2d\u6d89\u53ca\u7684\u985e\u578b\u53ef\u4ee5\u96b1\u5f0f\u8f49\u63db\u800c\u4e0d\u6703\u51fa\u73fe\u554f\u984c\u3002\u5982\u6709\u5fc5\u8981\uff0c\u8acb\u4f7f\u7528\u524d\u9762\u63d0\u5230\u7684\u660e\u78ba\u985e\u578b\u8f49\u63db\u3002<\/p>\n<h2>\u7e3d\u7d50<\/h2>\n<p>\u7e3d\u4e4b\uff0cPostgreSQL \u932f\u8aa4\u4ee3\u78bc\uff1a42804 &#8211; datatype_mismatch \u767c\u751f\u5728\u5217\u7684\u6578\u64da\u985e\u578b\u8207\u88ab\u63d2\u5165\u6216\u66f4\u65b0\u7684\u503c\u4e4b\u9593\u4e0d\u5339\u914d\u6642\u3002\u8981\u4fee\u5fa9\u6b64\u932f\u8aa4\uff0c\u8acb\u9a57\u8b49\u6578\u64da\u985e\u578b\u3001\u63d0\u4f9b\u6709\u6548\u503c\u3001\u5728\u5fc5\u8981\u6642\u4f7f\u7528\u660e\u78ba\u7684\u985e\u578b\u8f49\u63db\uff0c\u4e26\u6aa2\u67e5\u96b1\u5f0f\u985e\u578b\u8f49\u63db\u554f\u984c\u3002\u901a\u904e\u9075\u5faa\u9019\u4e9b\u6b65\u9a5f\uff0c\u60a8\u53ef\u4ee5\u89e3\u6c7a datatype_mismatch \u932f\u8aa4\uff0c\u78ba\u4fdd\u60a8\u7684 PostgreSQL \u6578\u64da\u5eab\u6b63\u5e38\u904b\u884c\u3002<\/p>\n<p>\u5982\u9700\u53ef\u9760\u4e14\u9ad8\u6548\u80fd\u7684 VPS \u8a17\u7ba1\u89e3\u6c7a\u65b9\u6848\uff0c\u8acb\u8003\u616e <a href=\"https:\/\/server.hk\">Server.HK<\/a>\u3002\u6211\u5011\u7684\u9999\u6e2f VPS \u8a17\u7ba1\u670d\u52d9\u70ba\u60a8\u7684 PostgreSQL \u548c\u5176\u4ed6\u6578\u64da\u5eab\u9700\u6c42\u63d0\u4f9b\u4e00\u6d41\u7684\u6027\u80fd\u548c\u53ef\u9760\u6027\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u4fee\u5fa9 PostgreSQL &#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4925],"tags":[],"class_list":["post-21406","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/21406","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=21406"}],"version-history":[{"count":2,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/21406\/revisions"}],"predecessor-version":[{"id":24087,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/21406\/revisions\/24087"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=21406"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=21406"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=21406"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}