1

sqlyog を介して外部キー制約を追加しようとしていますが、このエラーが発生しますが、1 つのソースと 1 つの参照列しか選択していません。

出典と参考文献を同数選択してください

この場合の意味を知っている人はいますか?ソース列と参照列の数が同じであることに注意してください...

4

1 に答える 1

2

I came across the same issue with SQLYog v9.01. The error message is misleading and the real cause of an error can be totally different.

Things I checked to solve this are the following:

  • Check table engyne types, should be both InnoDb
  • Check if your target table is not the same as source.
  • Check datatypes, length and charset collation of referenced fields.
  • If you already have data in your tables check its consistency.

For example, you should remove all unrelated data from table B which relates to table A

 DELETE target FROM B AS target LEFT JOIN A USING(id_A) WHERE A.id_A IS NULL
  • Finally ones in my case I had to FLUSH tables to create my constraints successfully.

Manual constraint creation from Query window can give you more information on your error type.

Just a reminder:

ALTER TABLE `B` ADD CONSTRAINT `FK_B` FOREIGN KEY (`id_A`) REFERENCES `A` (`id_A`) ON DELETE CASCADE ; 

Good luck!

于 2012-12-28T17:24:58.970 に答える