在PostgreSQL中删除带有外键的行

我想删除包含外键的行,但当我尝试这样的:
DELETE FROM osoby WHERE id_osoby='1'

我得到这个声明:

ERROR: update or delete on table “osoby” violates foreign key constraint “kontakty_ibfk_1” on table “kontakty”
DETAIL: Key (id_osoby)=(1) is still referenced from table “kontakty”.

如何删除这些行?

自动化,可以使用ON DELETE CASCADE定义外键约束。
我引用 the manual of foreign key constraints

CASCADE specifies that when a referenced row is deleted,row(s) referencing it should be automatically deleted as well.

相关文章

项目需要,有个数据需要导入,拿到手一开始以为是mysql,结果...
本文小编为大家详细介绍“怎么查看PostgreSQL数据库中所有表...
错误现象问题原因这是在远程连接时pg_hba.conf文件没有配置正...
因本地资源有限,在公共测试环境搭建了PGsql环境,从数据库本...
wamp 环境 这个提示就是说你的版本低于10了。 先打印ph...
psycopg2.OperationalError: SSL SYSCALL error: EOF detect...