IN my mysql database i have two table review and products
mysql> desc review; +---------------+--------------+------+-----+-------------------+----------------+ | Field | Type | Null | Key | Default | Extra | +---------------+--------------+------+-----+-------------------+----------------+ | id | int(11) | NO | PRI | NULL | auto_increment | | review | varchar(255) | YES | | NULL | | | rating | varchar(255) | YES | | NULL | | | created_at | timestamp | NO | | CURRENT_TIMESTAMP | | | updated_at | timestamp | NO | | CURRENT_TIMESTAMP | | | reviewer_name | varchar(255) | YES | | NULL | | | product_id | int(11) | YES | | NULL | | +---------------+--------------+------+-----+-------------------+----------------+ mysql> desc products; +---------+------------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +---------+------------------+------+-----+---------+----------------+ | id | int(10) unsigned | NO | PRI | NULL | auto_increment | | name | varchar(255) | NO | | NULL | | | details | text | NO | | NULL | | +---------+------------------+------+-----+---------+----------------+ 3 rows in set (0.00 sec) When i try to make product_id in review table as foreign key that refer to id in products table i found this error and the query what i gave was:
mysql> ALTER TABLE review ADD FOREIGN KEY (product_id) REFERENCES products(id); ERROR 1215 (HY000): Cannot add foreign key constraint Please help me out what the problem is and how can i figure it out