二つの簡単なサンプル sql ファイルを作成しました。
しかし、child テーブルを import しようとすると「child テーブルのインポートエラー」のメッセージが出てきて入りません。
parent テーブルの index の順番が Attribute カラムが一番上だとうまく入ります。
外部キー参照をする場合、参照先のテーブル構造は複合キーを扱えないのでしょうか?
■child テーブルのインポートエラー
[ERROR in query 1] Failed to add the foreign key constraint. Missing index for constraint 'Attribute_fk' in the referenced table 'parent'
■parent.sql
CREATE TABLE `parent` ( `Parent` int(10) NOT NULL, `Attribute` varchar(200) NOT NULL, PRIMARY KEY ( `Parent`, `Attribute` ) ) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4; -- CREATE TABLE `parent` -- ( -- `Attribute` varchar(200) NOT NULL, -- `Parent` int(10) NOT NULL, -- PRIMARY KEY ( -- `Attribute`, -- `Parent` -- ) -- ) ENGINE = InnoDB -- DEFAULT CHARSET = utf8mb4; → Attribute カラムが一番上だと child テーブルがインポートできます。
■child.sql
CREATE TABLE `child` ( `Name` varchar(200) NOT NULL, `Attribute` varchar(200) NOT NULL, `Parent` int(10) NOT NULL, PRIMARY KEY (`Name`), CONSTRAINT `Attribute_fk` FOREIGN KEY (`Attribute`) REFERENCES `parent` (`Attribute`) -- CONSTRAINT `Parent_fk` FOREIGN KEY (`Parent`) REFERENCES `parent` (`Parent`) ) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4;
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。