将 .sql 文件加载到 Postgres 数据库时出现约束问题
Constraint Issue When Loading .sql file into Postgres DB
我对整个生产数据库执行了 pg_dump
,并尝试将其上传到新迁移的干净 Postgres DB 本地。当我执行 psal db_name < data.sql
时,我会收到这样的错误
insert or update on table "vehicle_vehicle" violates foreign key constraint "vehicle_vehi_vehicle_make_id_265a8146_fk_vehicle_vehiclemake_id"
DETAIL: Key (vehicle_make_id)=(788) is not present in table "vehicle_vehiclemake".
我的问题是:
当一个table试图加载外键,而另一个table有尚未上传的外键关系时,Postgres会停止吗?正在做并开始加载 table?
加载数据如何解决这个问题?由 table 转储数据 table 并一次加载一个吗?
使用 pg_restore
和 --clean
从头开始恢复您的数据库。如果以下是完整转储,则应在设置外键之前插入数据,这样就不会有问题。
我对整个生产数据库执行了 pg_dump
,并尝试将其上传到新迁移的干净 Postgres DB 本地。当我执行 psal db_name < data.sql
时,我会收到这样的错误
insert or update on table "vehicle_vehicle" violates foreign key constraint "vehicle_vehi_vehicle_make_id_265a8146_fk_vehicle_vehiclemake_id"
DETAIL: Key (vehicle_make_id)=(788) is not present in table "vehicle_vehiclemake".
我的问题是:
当一个table试图加载外键,而另一个table有尚未上传的外键关系时,Postgres会停止吗?正在做并开始加载 table?
加载数据如何解决这个问题?由 table 转储数据 table 并一次加载一个吗?
使用 pg_restore
和 --clean
从头开始恢复您的数据库。如果以下是完整转储,则应在设置外键之前插入数据,这样就不会有问题。