简体   繁体   English

删除更新表的约束 - 当前事务被中止

[英]Dropping constraints to update tables - Current transaction is aborted

Context: I want to update a table called "Projects" and change the project number from 10 to 45 where the project name is "Website".上下文:我想更新一个名为“项目”的表,并将项目编号从 10 更改为 45,其中项目名称为“网站”。 This Project table has a PK (pnumber attribute) and its related to another table called "WorksOn" that has a FK (attribute pno) related to the primary key pnumber of Project table.该项目表有一个 PK(pnumber 属性),它与另一个名为“WorksOn”的表相关,该表具有与项目表的主键 pnumber 相关的 FK(属性 pno)。

The diagram would be something like this:该图将是这样的:

在此处输入图像描述

I was trying something like:我正在尝试类似的东西:

BEGIN TRANSACTION;
    ALTER TABLE Workson DROP CONSTRAINT fk_workson_projects;
    ALTER TABLE Projects DROP CONSTRAINT pk_projects;
    UPDATE Projects
        SET pnumber = 45
    WHERE pname = 'Website';
    ALTER TABLE Workson ADD CONSTRAINT fk_workson_projects FOREIGN KEY (pno) REFERENCES projects(pnumber);
    ALTER TABLE Projects ADD CONSTRAINT pk_projects PRIMARY KEY (pnumber);

COMMIT;

Essentially dropping the constraints, updating the table and adding the same constraints again but I keep getting this error:本质上是删除约束、更新表并再次添加相同的约束,但我不断收到此错误:

ERROR:  current transaction is aborted, commands ignored until end of transaction block
SQL state: 25P02

How could I update the information by dropping the constraints and adding them back again inside a transaction?我如何通过删除约束并将它们重新添加到事务中来更新信息?

Thank you in advance先感谢您

You need to create the primary key before you can create a foreign key that references it.您需要先创建主键,然后才能创建引用它的外键。 Looking at the error messages would have told you that.查看错误消息会告诉您这一点。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 PGError:错误:当前事务中止 - PGError: ERROR: current transaction is aborted 禁止在PostgreSQL中显示“当前事务中止…”消息 - Suppress “current transaction is aborted…” messages in PostgreSQL PSQL:当前事务中止,命令被忽略,直到事务块结束 - PSQL: current transaction is aborted, commands ignored until end of transaction block InternalError:当前事务中止,命令被忽略,直到事务块结束 - InternalError: current transaction is aborted, commands ignored until end of transaction block DatabaseError:当前事务被中止,在事务块结束之前忽略命令? - DatabaseError: current transaction is aborted, commands ignored until end of transaction block? PSQLException:当前事务被中止,命令被忽略直到事务块结束 - PSQLException: current transaction is aborted, commands ignored until end of transaction block 当前事务被中止,命令被忽略直到事务结束 - Current transaction is aborted, commands ignored until end of transaction 在rails3迁移中,“PGError:错误:当前事务被中止” - “PGError: ERROR: current transaction is aborted” in rails3 migration jOOQ + Spring:PSQLException:当前事务中止,命令被忽略,直到事务结束 - jOOQ + Spring : PSQLException: current transaction is aborted, commands ignored until end of transaction InternalError:当前事务被中止,命令被忽略,直到事务块结束(受UNIQUE约束) - InternalError: current transaction is aborted, commands ignored until end of transaction block ,on UNIQUE constraint
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM