postgresql - 如何使用 psql 恢复具有关系的数据库?
问题描述
我正在尝试使用 psql 恢复数据库。但似乎 psql 在遇到时总是失败CONSTRAINT
。在我查看垃圾场之后。我发现子表,即持有的表FOREIGN KEY
,是在父表之前创建的。
这是片段...
DROP TABLE IF EXISTS "answer";
DROP SEQUENCE IF EXISTS answer_id_seq;
CREATE SEQUENCE answer_id_seq INCREMENT 1 MINVALUE 1 MAXVALUE 2147483647 START 71 CACHE 1;
CREATE TABLE "public"."answer" (
"id" integer DEFAULT nextval('answer_id_seq') NOT NULL,
"text" character varying NOT NULL,
"weight" double precision NOT NULL,
"questionId" integer NOT NULL,
"baseCreated" timestamp DEFAULT now() NOT NULL,
"baseUpdated" timestamp DEFAULT now() NOT NULL,
CONSTRAINT "PK_9232db17b63fb1e94f97e5c224f" PRIMARY KEY ("id"),
CONSTRAINT "FK_a4013f10cd6924793fbd5f0d637" FOREIGN KEY ("questionId") REFERENCES question(id) ON DELETE CASCADE NOT DEFERRABLE
) WITH (oids = false);
psql 命令。
psql -h 0.0.0.0 -p 5432 -U foobar -1 foobar < foobar.sql
和错误。
NOTICE: table "answer" does not exist, skipping
DROP TABLE
NOTICE: sequence "answer_id_seq" does not exist, skipping
DROP SEQUENCE
CREATE SEQUENCE
ERROR: relation "question" does not exist
ERROR: relation "answer" does not exist
ERROR: relation "answer" does not exist
LINE 1: INSERT INTO "answer" ("id", "text", "weight", "questionId", ...
解决方案
推荐阅读
- c++ - 使用 libcxx 和 std::atomic,如何通过默认构造函数清除 std::atomic_flag?
- reactjs - 使用 redux 和 webpack 反应 SSR 优化后 Gtmetrix 分数不会增加
- javascript - 从 Python 脚本获取输入到 Node.js Telegram Bot
- python-3.x - tf.tape.gradient() 返回无
- sql - 概括 CASE 语句(结果列的动态名称?)
- python - 从 csv 数据创建树结构以用于折叠菜单
- c++ - 辅助类型别名与继承
- python - 使用 selenium 获取 img 标签的 alt 属性值
- python-3.x - python38.dll 在 windows 10 中被自动删除
- log4j2 - rsyslog 服务器正在使用原始日志文件生成另一组日志文件