I had already created the database and all tables
with foreign key constraints
, but I had a column in parent table
which was unique
and was part of composite key
, so I had to drop
all foreign key constraints
from all child tables
and then drop
ped the unique constraint
on parent table
.
Now when I am adding foreign key constraint
back to all child tables
, it gives error
: foreign key constraint
is incorrectly formed, although I have checked both my parent and child table columns
and they are of same type
using same engine
, unicode
and all. But still this is thrown.
When I checked the table
structure of child table
, it has an index
defined for the foreign key
and the column
is child column foreign key
, so I tried after removing it but still error
.
Query
ALTER TABLE `child_table` ADD CONSTRAINT FOREIGN KEY `fk_parent_table_child_table_column_name` (child_table_column_name)
REFERENCES `parent_table`(parent_table_column_name) ON DELETE RESTRICT ON UPDATE NO ACTION;
both columns
are VARCHAR PRIMARY KEY and NOT NULL
If more information is required please ask.
EDIT
So far I have tried to drop
ped the index
, drop
ped the PRIMARY KEY CONSTRAINT
from child table
and drop
ping the column
then adding it back with VARCHAR(14), NOT NULL
, still no success.
EDIT 2
Also tried to add
the child column
in primary key
and then tried to apply foreign key constraint
, no success so far.