mysqlforeign-keysforeign-key-relationshipmysql-error-1025

unable to drop the foreign key


I would like to drop the foreign key in my table but been into this error message

mysql> alter table customers drop foreign key customerid;
ERROR 1025 (HY000): Error on rename of '.\products\customers' to '.\products\#sql2-7ec-a3' (errno: 152)
mysql>

Solution

  • To avoid getting this error while trying to drop a foreign key, use the constraint name rather than the column name of the foreign key.

    When I tried

    mysql> ALTER TABLE mytable DROP PRIMARY KEY;
    

    I got error as

    ERROR 1025 (HY000): Error on rename of '.\database\#sql-454_3' to '.\database\mytable' (errno: 150).
    

    I solved it using:

    mysql> ALTER TABLE mytable DROP PRIMARY KEY, ADD PRIMARY KEY (column1,column2,column3);
    

    Some links that will help you.

    link 1

    link 2 [look for Posted by Alex Blume on November 7 2008 5:09pm & Posted by Hector Delgadillo on January 21 2011 4:57am]