Postgresql 如何替换列中的字符串,该列是另一个表中的外键

Postgresql 如何替换列中的字符串,该列是另一个表中的外键,postgresql,foreign-key-relationship,Postgresql,Foreign Key Relationship,我正在尝试使用SQL替换查询: UPDATE mytable SET theId = Replace(theId, 'E', 'T') 问题是theId是另一个表mytable2asThe number 我得到的错误是: ERROR: insert or update on table "mytable" violates foreign key constraint "mytable_theId_a0b4efa1_fk_mytable2_theNumber" SQL state: 23503

我正在尝试使用SQL替换查询:

UPDATE mytable SET theId = Replace(theId, 'E', 'T')
问题是
theId
是另一个表
mytable2
as
The number

我得到的错误是:

ERROR: insert or update on table "mytable" violates foreign key constraint "mytable_theId_a0b4efa1_fk_mytable2_theNumber"
SQL state: 23503
Detail: Key (theId)=(763755.46T292326.83N) is not present in table "mytable2".
这就像我必须同时做一个连接替换或其他什么,不知道怎么做。或者也许我必须改变表格以简单地摆脱关系,进行更改并以某种方式重新添加关系?(不知道如何删除密钥等)(查看pgAdminIII,我甚至看不到在哪里可以获得要删除和重新添加的密钥的名称)

我试图更改一些值,基本上是字符串替换

763755.46E292326.83N

Alter table myTable2 DROP CONSTRAINT mytable_theId_a0b4efa1_fk_mytable2_theNumber 

UPDATE mytable SET theId = Replace(theId, 'E', 'T')

Alter table myTable2  ADD CONSTRAINT FK_myTable2_theID FOREIGN KEY(theNumber) REFERENCES myTable2(theId)
为此:


763755.46T292326.83N

好的,我得到了更新,但是添加我的外键给了我一个错误:错误:语法错误在“foreign”行或附近1:Alter table mytable ADD CONSTRAINT外键(。。。
Alter table myTable2 DROP CONSTRAINT mytable_theId_a0b4efa1_fk_mytable2_theNumber 

UPDATE mytable SET theId = Replace(theId, 'E', 'T')

Alter table myTable2  ADD CONSTRAINT FK_myTable2_theID FOREIGN KEY(theNumber) REFERENCES myTable2(theId)