2017-02-21 139 views
0

我有一个表主键为voucher_no (varchar(10)),我试图从另一个新表创建FK到这个表/列,但是我我得到一个错误:引用表中没有与引用列相匹配的主键或候选键

There are no primary or candidate keys in the referenced table 'apinv_hdr' that match the referencing column list in the foreign key 'fk_invoice_cfdi_x_voucher_apinv_hdr'

我有几个其他FK绑在这个表/列 - 为什么现在这样反应?

+2

什么是新表的主键? –

+3

请品尝两个表的结构以及两个表中的约束 –

回答

0

主键和外键数据类型必须匹配。你是否验证过列数据类型是否相同?

0

看起来像voucher_no记录在another new table不存在voucher_nomain table。 下面的脚本可能会对您有所帮助。

select * 
from another_new_table 
where voucher_no not in (select voucher_no 
          from main_table) 

如果上面的查询返回行,你有两个选择:

删除another_new_table这些记录或 记录插入MAIN_TABLE

相关问题