{"id":21416,"date":"2024-01-02T09:01:26","date_gmt":"2024-01-02T09:01:26","guid":{"rendered":"https:\/\/server.hk\/blog\/21416\/"},"modified":"2024-11-14T10:34:49","modified_gmt":"2024-11-14T02:34:49","slug":"how-to-fix-postgresql-error-code-42704-undefined_object","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/21416\/","title":{"rendered":"\u5982\u4f55\u4fee\u5fa9 PostgreSQL \u932f\u8aa4\u4ee3\u78bc\uff1a42704 &#8211; undefined_object"},"content":{"rendered":"<h1 id=\"how-to-fix-postgresql-error-code-42704-undefined_object-HHjWiwoqKG\">\u5982\u4f55\u4fee\u5fa9 PostgreSQL \u932f\u8aa4\u4ee3\u78bc\uff1a42704 &#8211; undefined_object<\/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\u5168\u7403\u7684\u958b\u767c\u8005\u548c\u4f01\u696d\u4e2d\u3002\u7136\u800c\uff0c\u548c\u5176\u4ed6\u8edf\u4ef6\u4e00\u6a23\uff0c\u5b83\u4e5f\u7121\u6cd5\u907f\u514d\u932f\u8aa4\u548c\u554f\u984c\u3002PostgreSQL \u4f7f\u7528\u8005\u53ef\u80fd\u6703\u9047\u5230\u7684\u4e00\u500b\u5e38\u898b\u932f\u8aa4\u662f &#8220;42704 &#8211; undefined_object&#8221; \u932f\u8aa4\u4ee3\u78bc\u3002\u5728\u672c\u6587\u4e2d\uff0c\u6211\u5011\u5c07\u63a2\u8a0e\u8a72\u932f\u8aa4\u7684\u542b\u7fa9\u4e26\u63d0\u4f9b\u4fee\u5fa9\u6b65\u9a5f\u3002<\/p>\n<h2 id=\"understanding-the-error-HHjWiwoqKG\">\u4e86\u89e3\u932f\u8aa4<\/h2>\n<p>PostgreSQL \u4e2d\u7684 &#8220;42704 &#8211; undefined_object&#8221; \u932f\u8aa4\u4ee3\u78bc\u8868\u793a\u5728\u67e5\u8a62\u4e2d\u5f15\u7528\u7684\u5c0d\u8c61\u5728\u6578\u64da\u5eab\u4e2d\u4e0d\u5b58\u5728\u3002\u9019\u500b\u5c0d\u8c61\u53ef\u4ee5\u662f\u8868\u3001\u5217\u3001\u8996\u5716\u3001\u51fd\u6578\u6216\u5176\u4ed6\u4efb\u4f55\u6578\u64da\u5eab\u5be6\u9ad4\u3002\u7576 PostgreSQL \u9047\u5230\u6b64\u932f\u8aa4\u6642\uff0c\u610f\u5473\u8457\u88ab\u5f15\u7528\u7684\u5c0d\u8c61\u5728\u6307\u5b9a\u7684 schema \u6216\u6578\u64da\u5eab\u4e2d\u4e26\u4e0d\u5b58\u5728\u3002<\/p>\n<h2 id=\"causes-of-the-error-HHjWiwoqKG\">\u932f\u8aa4\u7684\u539f\u56e0<\/h2>\n<p>\u53ef\u80fd\u6703\u6709\u5e7e\u500b\u539f\u56e0\u5c0e\u81f4\u60a8\u5728 PostgreSQL \u4e2d\u9047\u5230 &#8220;42704 &#8211; undefined_object&#8221; \u932f\u8aa4\uff1a<\/p>\n<ul>\n<li><strong>\u5c0d\u8c61\u672a\u5275\u5efa\uff1a<\/strong>\u88ab\u5f15\u7528\u7684\u5c0d\u8c61\u672a\u88ab\u5275\u5efa\u6216\u5728\u6578\u64da\u5eab\u4e2d\u4e0d\u5b58\u5728\u3002<\/li>\n<li><strong>\u932f\u8aa4\u7684 schema\uff1a<\/strong>\u5c0d\u8c61\u5b58\u5728\uff0c\u4f46\u4f4d\u65bc\u67e5\u8a62\u4e2d\u6307\u5b9a\u7684 schema \u4e4b\u5916\u3002<\/li>\n<li><strong>\u5c0d\u8c61\u540d\u7a31\u62fc\u5beb\u932f\u8aa4\uff1a<\/strong>\u67e5\u8a62\u4e2d\u6307\u5b9a\u7684\u5c0d\u8c61\u540d\u7a31\u62fc\u5beb\u932f\u8aa4\u6216\u8207\u6578\u64da\u5eab\u4e2d\u7684\u5be6\u969b\u5c0d\u8c61\u540d\u7a31\u4e0d\u5339\u914d\u3002<\/li>\n<li><strong>\u5c0d\u8c61\u5df2\u522a\u9664\u6216\u91cd\u547d\u540d\uff1a<\/strong>\u5c0d\u8c61\u5728\u67e5\u8a62\u7de8\u5beb\u5f8c\u88ab\u522a\u9664\u6216\u91cd\u547d\u540d\uff0c\u5c0e\u81f4\u5f15\u7528\u7121\u6548\u3002<\/li>\n<\/ul>\n<h2 id=\"fixing-the-error-HHjWiwoqKG\">\u4fee\u5fa9\u932f\u8aa4<\/h2>\n<p>\u8981\u4fee\u5fa9 PostgreSQL \u4e2d\u7684 &#8220;42704 &#8211; undefined_object&#8221; \u932f\u8aa4\uff0c\u8acb\u6309\u7167\u4ee5\u4e0b\u6b65\u9a5f\u64cd\u4f5c\uff1a<\/p>\n<h3 id=\"1-check-object-existence-HHjWiwoqKG\">1. \u6aa2\u67e5\u5c0d\u8c61\u5b58\u5728\u6027<\/h3>\n<p>\u9a57\u8b49\u88ab\u5f15\u7528\u7684\u5c0d\u8c61\u5728\u6578\u64da\u5eab\u4e2d\u78ba\u5be6\u5b58\u5728\u3002\u4f7f\u7528\u9069\u7576\u7684 SQL \u547d\u4ee4\u6aa2\u67e5\u5c0d\u8c61\u7684\u5b58\u5728\u6027\uff1a<\/p>\n<pre><code>SELECT EXISTS (SELECT 1 FROM pg_catalog.pg_class WHERE relname = 'object_name');<\/code><\/pre>\n<p>\u5c07 &#8216;object_name&#8217; \u66ff\u63db\u70ba\u60a8\u5f15\u7528\u7684\u5c0d\u8c61\u540d\u7a31\u3002\u5982\u679c\u67e5\u8a62\u8fd4\u56de &#8216;true&#8217;\uff0c\u5247\u8868\u793a\u8a72\u5c0d\u8c61\u5b58\u5728\u3002\u5982\u679c\u8fd4\u56de &#8216;false&#8217;\uff0c\u5247\u8868\u793a\u5c0d\u8c61\u4e0d\u5b58\u5728\uff0c\u60a8\u9700\u8981\u5275\u5efa\u5b83\u3002<\/p>\n<h3 id=\"2-verify-schema-HHjWiwoqKG\">2. \u9a57\u8b49 schema<\/h3>\n<p>\u5982\u679c\u5c0d\u8c61\u5b58\u5728\uff0c\u8acb\u78ba\u4fdd\u60a8\u5728\u6b63\u78ba\u7684 schema \u4e2d\u5f15\u7528\u5b83\u3002\u4f7f\u7528\u4ee5\u4e0b SQL \u547d\u4ee4\u6aa2\u67e5\u5c0d\u8c61\u7684 schema\uff1a<\/p>\n<pre><code>SELECT table_schema FROM information_schema.tables WHERE table_name = 'object_name';<\/code><\/pre>\n<p>\u5c07 &#8216;object_name&#8217; \u66ff\u63db\u70ba\u60a8\u5f15\u7528\u7684\u5c0d\u8c61\u540d\u7a31\u3002\u5c07\u67e5\u8a62\u8fd4\u56de\u7684 schema \u8207\u60a8\u67e5\u8a62\u4e2d\u6307\u5b9a\u7684 schema \u9032\u884c\u6bd4\u8f03\u3002\u5982\u679c\u4e0d\u540c\uff0c\u8acb\u66f4\u65b0\u60a8\u7684\u67e5\u8a62\u4ee5\u5f15\u7528\u6b63\u78ba\u7684 schema\u3002<\/p>\n<h3 id=\"3-check-object-name-HHjWiwoqKG\">3. \u6aa2\u67e5\u5c0d\u8c61\u540d\u7a31<\/h3>\n<p>\u4ed4\u7d30\u6aa2\u67e5\u67e5\u8a62\u4e2d\u5c0d\u8c61\u540d\u7a31\u7684\u62fc\u5beb\u548c\u5927\u5c0f\u5beb\u3002PostgreSQL \u662f\u5927\u5c0f\u5beb\u654f\u611f\u7684\uff0c\u56e0\u6b64\u8acb\u78ba\u4fdd\u67e5\u8a62\u4e2d\u7684\u5c0d\u8c61\u540d\u7a31\u8207\u6578\u64da\u5eab\u4e2d\u7684\u5be6\u969b\u5c0d\u8c61\u540d\u7a31\u76f8\u5339\u914d\u3002<\/p>\n<h3 id=\"4-handle-object-changes-HHjWiwoqKG\">4. \u8655\u7406\u5c0d\u8c61\u8b8a\u66f4<\/h3>\n<p>\u5982\u679c\u5c0d\u8c61\u5728\u67e5\u8a62\u7de8\u5beb\u5f8c\u88ab\u522a\u9664\u6216\u91cd\u547d\u540d\uff0c\u60a8\u9700\u8981\u76f8\u61c9\u5730\u4fee\u6539\u67e5\u8a62\u3002\u66f4\u65b0\u67e5\u8a62\u4ee5\u5f15\u7528\u65b0\u5c0d\u8c61\u540d\u7a31\u6216\u91cd\u65b0\u5275\u5efa\u5df2\u522a\u9664\u7684\u5c0d\u8c61\u3002<\/p>\n<h2 id=\"summary-HHjWiwoqKG\">\u7e3d\u7d50<\/h2>\n<p>PostgreSQL \u4e2d\u7684 &#8220;42704 &#8211; undefined_object&#8221; \u932f\u8aa4\u8868\u793a\u5728\u67e5\u8a62\u4e2d\u5f15\u7528\u7684\u5c0d\u8c61\u5728\u6578\u64da\u5eab\u4e2d\u4e0d\u5b58\u5728\u3002\u8981\u4fee\u5fa9\u6b64\u932f\u8aa4\uff0c\u60a8\u9700\u8981\u9a57\u8b49\u5c0d\u8c61\u7684\u5b58\u5728\u6027\uff0c\u6aa2\u67e5 schema\uff0c\u78ba\u4fdd\u5c0d\u8c61\u540d\u7a31\u7684\u62fc\u5beb\u6b63\u78ba\uff0c\u4e26\u8655\u7406\u4efb\u4f55\u5c0d\u8c61\u8b8a\u66f4\u3002\u901a\u904e\u9075\u5faa\u9019\u4e9b\u6b65\u9a5f\uff0c\u60a8\u53ef\u4ee5\u89e3\u6c7a\u932f\u8aa4\u4e26\u7121\u7e2b\u5730\u7e7c\u7e8c\u4f7f\u7528 PostgreSQL\u3002<\/p>\n<p>\u5c0d\u65bc\u53ef\u9760\u548c\u9ad8\u6027\u80fd\u7684 VPS \u8a17\u7ba1\u89e3\u6c7a\u65b9\u6848\uff0c\u8acb\u8003\u616e <a href=\"https:\/\/server.hk\">Server.HK<\/a>\u3002\u901a\u904e\u6211\u5011\u9802\u5c16\u7684 VPS \u8a17\u7ba1\u670d\u52d9\uff0c\u60a8\u53ef\u4ee5\u78ba\u4fdd PostgreSQL \u6578\u64da\u5eab\u53ca\u5176\u4ed6\u61c9\u7528\u7a0b\u5e8f\u7684\u9806\u5229\u904b\u884c\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-21416","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/21416","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=21416"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/21416\/revisions"}],"predecessor-version":[{"id":24077,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/21416\/revisions\/24077"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=21416"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=21416"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=21416"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}