[英]PostgreSQL : Transaction and foreign key problem
I'm inserting a value in table A, that has a serial type as primary key. 我在表A中插入一个值,它有一个串行类型作为主键。 I wanna use the returned value of the query as a foreign key of table B... but I get this message:
我想使用查询的返回值作为表B的外键...但我收到此消息:
ERROR: insert or update on table "tb_midia_pessoa" violates foreign key constraint "tb_midia_pessoa_id_pessoa_fkey" DETAIL: Key (id_pessoa)=(30) is not present in table "tb_pessoa". 错误:在表“tb_midia_pessoa”上插入或更新违反外键约束“tb_midia_pessoa_id_pessoa_fkey”DETAIL:键(id_pessoa)=(30)不存在于表“tb_pessoa”中。 )
)
How can I make this possible without: - starting a new Transaction - droping my foreign keys constraints =O ? 如果没有: - 启动一个新的事务 - 删除我的外键约束= O?
Regards! 问候! Pedro
佩德罗
You can make a deferrable FK, just use DEFERRABLE and maybe INITIALLY DEFERRED, that's up to you. 您可以制作一个可推迟的FK,只需使用DEFERRABLE并且可能是最初的,这取决于您。
http://www.postgresql.org/docs/current/static/sql-createtable.html http://www.postgresql.org/docs/current/static/sql-createtable.html
The statement below allows non-deferrable constraints to be deferred until transaction committed. 下面的语句允许延迟非延迟约束,直到事务提交。 If you don't want to change FK definitions.
如果您不想更改FK定义。
SET CONSTRAINTS ALL DEFERRED;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.