2017-02-21 37 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

相關問題