问题描述
我在表A中插入一个值,它有一个串行类型作为主键。我想使用查询的返回值作为表B的外键...但我得到这个消息:
$ b
错误:在表上插入或更新tb_midia_pessoa违反了外键约束tb_midia_pessoa_id_pessoa_fkey详细信息:键(id_pessoa)=(30)在表tb_pessoa中不存在。 ) 如何在不使用 问候! 您可以创建一个可延迟的FK,只需使用DEFERRABLE,也许是INITIALLY DEFERRED,这取决于您。 I'm inserting a value in table A, that has a serial type as primary key. I wanna use the returned value of the query as a foreign key of table B... but I get this message: 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". ) How can I make this possible without:- starting a new Transaction- droping my foreign keys constraints =O? Regards!Pedro You can make a deferrable FK, just use DEFERRABLE and maybe INITIALLY DEFERRED, that's up to you. http://www.postgresql.org/docs/current/static/sql-createtable.html 这篇关于PostgreSQL:交易和外键问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
的情况下启动新的事务
- 删除我的外键constraints = O
?
Pedro