command line - mysql errno 150 when creating foreign key -
i'm getting errno 150 , can't figure out why. i've read million other answers must have index set on parent column , i'm not sure why i'm still getting error.
parent table indexes:
mysql> show indexes plans; +-------+------------+----------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+ | table | non_unique | key_name | seq_in_index | column_name | collation | cardinality | sub_part | packed | null | index_type | comment | index_comment | +-------+------------+----------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+ | plans | 0 | primary | 1 | plan_id | | 86 | null | null | | btree | | | | plans | 0 | plan_id_unique | 1 | plan_id | | 86 | null | null | | btree | | | | plans | 1 | plan_id | 1 | plan_id | | 86 | null | null | | btree | | | +-------+------------+----------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+ 3 rows in set (0.08 sec) child table indexes:
mysql> show indexes promos; +--------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+ | table | non_unique | key_name | seq_in_index | column_name | collation | cardinality | sub_part | packed | null | index_type | comment | index_comment | +--------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+ | promos | 0 | primary | 1 | promo_id | | 0 | null | null | | btree | | | | promos | 1 | plan_id | 1 | plan_id | | 0 | null | null | | btree | | | +--------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+ 2 rows in set (0.06 sec) error:
mysql> alter table promos add foreign key (plan_id) references plans (plan_id) on delete cascade on update cascade; error 1005 (hy000): can't create table 'dev.#sql-2ce_599a' (errno: 150)
you have have same collation , character set both columns.
this works: http://sqlfiddle.com/#!2/0f917
Comments
Post a Comment