{"id":96774,"date":"2024-10-20T12:15:18","date_gmt":"2024-10-20T04:15:18","guid":{"rendered":"https:\/\/server.hk\/cnblog\/96774\/"},"modified":"2024-10-20T12:15:19","modified_gmt":"2024-10-20T04:15:19","slug":"postgresql-23000-integrity_constraint_violation-%e5%a0%b1%e9%8c%af-%e6%95%85%e9%9a%9c%e4%bf%ae%e5%be%a9-%e9%81%a0%e7%a8%8b%e8%99%95%e7%90%86","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/96774\/","title":{"rendered":"PostgreSQL 23000: integrity_constraint_violation \u5831\u932f \u6545\u969c\u4fee\u5fa9 \u9060\u7a0b\u8655\u7406"},"content":{"rendered":"<h1 id=\"postgresql-23000-integrity_constraint_violation-%e5%a0%b1%e9%8c%af-%e6%95%85%e9%9a%9c%e4%bf%ae%e5%be%a9-%e9%81%a0%e7%a8%8b%e8%99%95%e7%90%86-wVIrpluepz\">PostgreSQL 23000: integrity_constraint_violation \u5831\u932f \u6545\u969c\u4fee\u5fa9 \u9060\u7a0b\u8655\u7406<\/h1>\n<p>\u5728\u4f7f\u7528 PostgreSQL \u6578\u64da\u5eab\u6642\uff0c\u958b\u767c\u8005\u53ef\u80fd\u6703\u9047\u5230\u5404\u7a2e\u932f\u8aa4\uff0c\u5176\u4e2d\u4e4b\u4e00\u5c31\u662f <code>integrity_constraint_violation<\/code> \u932f\u8aa4\u3002\u9019\u500b\u932f\u8aa4\u901a\u5e38\u8207\u6578\u64da\u5b8c\u6574\u6027\u7d04\u675f\u6709\u95dc\uff0c\u7576\u6578\u64da\u5eab\u64cd\u4f5c\u9055\u53cd\u4e86\u9019\u4e9b\u7d04\u675f\u6642\uff0c\u5c31\u6703\u89f8\u767c\u6b64\u932f\u8aa4\u3002\u672c\u6587\u5c07\u6df1\u5165\u63a2\u8a0e\u9019\u500b\u932f\u8aa4\u7684\u539f\u56e0\u3001\u89e3\u6c7a\u65b9\u6848\u4ee5\u53ca\u5982\u4f55\u9032\u884c\u9060\u7a0b\u8655\u7406\u3002<\/p>\n<h2 id=\"%e4%bb%80%e9%ba%bc%e6%98%af-integrity_constraint_violation-%e9%8c%af%e8%aa%a4%ef%bc%9f-wVIrpluepz\">\u4ec0\u9ebc\u662f integrity_constraint_violation \u932f\u8aa4\uff1f<\/h2>\n<p>\u5728 PostgreSQL \u4e2d\uff0c\u6578\u64da\u5b8c\u6574\u6027\u7d04\u675f\u662f\u7528\u4f86\u78ba\u4fdd\u6578\u64da\u7684\u6e96\u78ba\u6027\u548c\u4e00\u81f4\u6027\u7684\u4e00\u7a2e\u6a5f\u5236\u3002\u7576\u6578\u64da\u5eab\u64cd\u4f5c\uff08\u5982\u63d2\u5165\u3001\u66f4\u65b0\u6216\u522a\u9664\uff09\u9055\u53cd\u4e86\u9019\u4e9b\u7d04\u675f\u6642\uff0c\u5c31\u6703\u7522\u751f <code>integrity_constraint_violation<\/code> \u932f\u8aa4\u3002\u5e38\u898b\u7684\u7d04\u675f\u5305\u62ec\uff1a<\/p>\n<ul>\n<li><strong>\u4e3b\u9375\u7d04\u675f\uff08Primary Key Constraint\uff09<\/strong>\uff1a\u78ba\u4fdd\u6bcf\u4e00\u884c\u7684\u552f\u4e00\u6027\u3002<\/li>\n<li><strong>\u5916\u9375\u7d04\u675f\uff08Foreign Key Constraint\uff09<\/strong>\uff1a\u78ba\u4fdd\u6578\u64da\u4e4b\u9593\u7684\u53c3\u7167\u5b8c\u6574\u6027\u3002<\/li>\n<li><strong>\u552f\u4e00\u7d04\u675f\uff08Unique Constraint\uff09<\/strong>\uff1a\u78ba\u4fdd\u67d0\u4e00\u5217\u7684\u503c\u5728\u6574\u500b\u8868\u4e2d\u662f\u552f\u4e00\u7684\u3002<\/li>\n<li><strong>\u6aa2\u67e5\u7d04\u675f\uff08Check Constraint\uff09<\/strong>\uff1a\u78ba\u4fdd\u5217\u4e2d\u7684\u6578\u64da\u7b26\u5408\u7279\u5b9a\u689d\u4ef6\u3002<\/li>\n<\/ul>\n<h2 id=\"%e5%b8%b8%e8%a6%8b%e7%9a%84%e9%8c%af%e8%aa%a4%e6%83%85%e5%a2%83-wVIrpluepz\">\u5e38\u898b\u7684\u932f\u8aa4\u60c5\u5883<\/h2>\n<p>\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u898b\u7684\u60c5\u5883\uff0c\u53ef\u80fd\u6703\u5c0e\u81f4 <code>integrity_constraint_violation<\/code> \u932f\u8aa4\uff1a<\/p>\n<ul>\n<li>\u5617\u8a66\u63d2\u5165\u4e00\u689d\u8a18\u9304\uff0c\u5176\u4e3b\u9375\u5df2\u5b58\u5728\u65bc\u8868\u4e2d\u3002<\/li>\n<li>\u5617\u8a66\u63d2\u5165\u4e00\u689d\u8a18\u9304\uff0c\u5176\u5916\u9375\u6307\u5411\u7684\u8a18\u9304\u5728\u53c3\u7167\u8868\u4e2d\u4e0d\u5b58\u5728\u3002<\/li>\n<li>\u5617\u8a66\u63d2\u5165\u4e00\u689d\u8a18\u9304\uff0c\u5176\u552f\u4e00\u7d04\u675f\u7684\u5217\u4e2d\u5df2\u5b58\u5728\u76f8\u540c\u7684\u503c\u3002<\/li>\n<li>\u5617\u8a66\u66f4\u65b0\u4e00\u689d\u8a18\u9304\uff0c\u4f7f\u5176\u9055\u53cd\u6aa2\u67e5\u7d04\u675f\u7684\u689d\u4ef6\u3002<\/li>\n<\/ul>\n<h2 id=\"%e6%95%85%e9%9a%9c%e4%bf%ae%e5%be%a9%e6%ad%a5%e9%a9%9f-wVIrpluepz\">\u6545\u969c\u4fee\u5fa9\u6b65\u9a5f<\/h2>\n<p>\u7576\u9047\u5230 <code>integrity_constraint_violation<\/code> \u932f\u8aa4\u6642\uff0c\u53ef\u4ee5\u6309\u7167\u4ee5\u4e0b\u6b65\u9a5f\u9032\u884c\u6545\u969c\u6392\u9664\uff1a<\/p>\n<h3 id=\"1-%e6%aa%a2%e6%9f%a5%e9%8c%af%e8%aa%a4%e4%bf%a1%e6%81%af-wVIrpluepz\">1. \u6aa2\u67e5\u932f\u8aa4\u4fe1\u606f<\/h3>\n<p>\u9996\u5148\uff0c\u4ed4\u7d30\u6aa2\u67e5\u932f\u8aa4\u4fe1\u606f\uff0c\u901a\u5e38\u6703\u63d0\u4f9b\u5177\u9ad4\u7684\u7d04\u675f\u540d\u7a31\u548c\u9055\u53cd\u7684\u6578\u64da\u3002\u9019\u53ef\u4ee5\u5e6b\u52a9\u4f60\u5feb\u901f\u5b9a\u4f4d\u554f\u984c\u3002<\/p>\n<h3 id=\"2-%e7%a2%ba%e8%aa%8d%e6%95%b8%e6%93%9a%e5%ae%8c%e6%95%b4%e6%80%a7%e7%b4%84%e6%9d%9f-wVIrpluepz\">2. \u78ba\u8a8d\u6578\u64da\u5b8c\u6574\u6027\u7d04\u675f<\/h3>\n<p>\u4f7f\u7528\u4ee5\u4e0b SQL \u67e5\u8a62\u4f86\u6aa2\u67e5\u8868\u7684\u7d04\u675f\uff1a<\/p>\n<pre><code>SELECT conname, contype \nFROM pg_constraint \nWHERE conrelid = 'your_table_name'::regclass;<\/code><\/pre>\n<p>\u9019\u5c07\u5217\u51fa\u6240\u6709\u8207\u6307\u5b9a\u8868\u76f8\u95dc\u7684\u7d04\u675f\uff0c\u5e6b\u52a9\u4f60\u4e86\u89e3\u54ea\u4e9b\u7d04\u675f\u53ef\u80fd\u88ab\u9055\u53cd\u3002<\/p>\n<h3 id=\"3-%e4%bf%ae%e6%ad%a3%e6%95%b8%e6%93%9a-wVIrpluepz\">3. \u4fee\u6b63\u6578\u64da<\/h3>\n<p>\u6839\u64da\u932f\u8aa4\u4fe1\u606f\u548c\u7d04\u675f\uff0c\u4fee\u6b63\u6578\u64da\u3002\u4f8b\u5982\uff0c\u5982\u679c\u662f\u4e3b\u9375\u7d04\u675f\u9055\u53cd\uff0c\u5247\u9700\u8981\u78ba\u4fdd\u63d2\u5165\u7684\u4e3b\u9375\u662f\u552f\u4e00\u7684\uff1b\u5982\u679c\u662f\u5916\u9375\u7d04\u675f\u9055\u53cd\uff0c\u5247\u9700\u8981\u78ba\u4fdd\u53c3\u7167\u7684\u8a18\u9304\u5b58\u5728\u3002<\/p>\n<h3 id=\"4-%e6%b8%ac%e8%a9%a6%e4%bf%ae%e5%be%a9-wVIrpluepz\">4. \u6e2c\u8a66\u4fee\u5fa9<\/h3>\n<p>\u5728\u4fee\u6b63\u6578\u64da\u5f8c\uff0c\u91cd\u65b0\u57f7\u884c\u539f\u59cb\u64cd\u4f5c\u4ee5\u78ba\u8a8d\u554f\u984c\u662f\u5426\u5df2\u89e3\u6c7a\u3002<\/p>\n<h2 id=\"%e9%81%a0%e7%a8%8b%e8%99%95%e7%90%86-wVIrpluepz\">\u9060\u7a0b\u8655\u7406<\/h2>\n<p>\u5728\u67d0\u4e9b\u60c5\u6cc1\u4e0b\uff0c\u958b\u767c\u8005\u53ef\u80fd\u9700\u8981\u9032\u884c\u9060\u7a0b\u8655\u7406\u4f86\u89e3\u6c7a <code>integrity_constraint_violation<\/code> \u932f\u8aa4\u3002\u9019\u53ef\u4ee5\u901a\u904e\u4ee5\u4e0b\u65b9\u5f0f\u5be6\u73fe\uff1a<\/p>\n<ul>\n<li><strong>\u4f7f\u7528 SSH \u9023\u63a5\u5230\u6578\u64da\u5eab\u4f3a\u670d\u5668<\/strong>\uff1a\u78ba\u4fdd\u4f60\u6709\u9069\u7576\u7684\u6b0a\u9650\u4f86\u8a2a\u554f\u6578\u64da\u5eab\u3002<\/li>\n<li><strong>\u4f7f\u7528 SQL \u5ba2\u6236\u7aef\u5de5\u5177<\/strong>\uff1a\u5982 pgAdmin \u6216 DBeaver\uff0c\u9019\u4e9b\u5de5\u5177\u53ef\u4ee5\u5e6b\u52a9\u4f60\u66f4\u76f4\u89c0\u5730\u7ba1\u7406\u6578\u64da\u5eab\u3002<\/li>\n<li><strong>\u57f7\u884c SQL \u67e5\u8a62<\/strong>\uff1a\u5728\u9060\u7a0b\u74b0\u5883\u4e2d\u57f7\u884c\u4e0a\u8ff0\u67e5\u8a62\u4f86\u6aa2\u67e5\u7d04\u675f\u548c\u6578\u64da\u3002<\/li>\n<\/ul>\n<h2 id=\"%e7%b8%bd%e7%b5%90-wVIrpluepz\">\u7e3d\u7d50<\/h2>\n<p>PostgreSQL \u7684 <code>integrity_constraint_violation<\/code> \u932f\u8aa4\u662f\u6578\u64da\u5b8c\u6574\u6027\u7d04\u675f\u9055\u53cd\u7684\u7d50\u679c\uff0c\u4e86\u89e3\u5176\u539f\u56e0\u548c\u89e3\u6c7a\u65b9\u6848\u5c0d\u65bc\u958b\u767c\u8005\u4f86\u8aaa\u81f3\u95dc\u91cd\u8981\u3002\u901a\u904e\u4ed4\u7d30\u6aa2\u67e5\u932f\u8aa4\u4fe1\u606f\u3001\u78ba\u8a8d\u7d04\u675f\u3001\u4fee\u6b63\u6578\u64da\u4ee5\u53ca\u9032\u884c\u9060\u7a0b\u8655\u7406\uff0c\u53ef\u4ee5\u6709\u6548\u5730\u89e3\u6c7a\u9019\u4e00\u554f\u984c\u3002\u5c0d\u65bc\u9700\u8981\u7a69\u5b9a\u548c\u9ad8\u6548\u6578\u64da\u5eab\u89e3\u6c7a\u65b9\u6848\u7684\u7528\u6236\uff0c\u9078\u64c7\u5408\u9069\u7684 <a href=\"https:\/\/server.hk\">VPS<\/a> \u6216 <a href=\"https:\/\/server.hk\">\u9999\u6e2f\u4f3a\u670d\u5668<\/a> \u662f\u4e00\u500b\u660e\u667a\u7684\u9078\u64c7\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u89e3\u6c7aPostgreSQL 23000: integrity_constraint_violation\u5831\u932f\u7684\u6545\u969c\u4fee\u5fa9\u65b9\u6cd5\uff0c\u63d0\u4f9b\u9060\u7a0b\u8655\u7406\u6280\u5de7\uff0c\u78ba\u4fdd\u6578\u64da\u5b8c\u6574\u6027\u3002<\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-96774","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/96774","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"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=96774"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/96774\/revisions"}],"predecessor-version":[{"id":96775,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/96774\/revisions\/96775"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=96774"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=96774"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=96774"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}