Delete a column using a foreign key

In my mysql DB with inno_db engine,

I have a table with a foreign key. I want to delete a column (along with the foreign key and corresponding index, of course, I don't need the whole column!)

Now, just dropping it, an error appears: General error: 1025 Error renaming '. \ Road_dmy # sql-19d8_2be' to '. \ Road_dmy \ contact' (errno: 150)

This seems to be a known issue. http://bugs.mysql.com/bug.php?id=15317

But anyway, what should I do to drop this column? I am very sure that it is possible, no one will use this database otherwise

(and btw how to find out the true details of the mysterious error message above?)

+5
source share
1 answer

First you need to drop the key. I do not know the names of your tables, but I will give you a general strategy using an example. Suppose you have the following 2 InnoDB tables:

CREATE TABLE `A` (
   `id` int(10) unsigned NOT NULL auto_increment,
    PRIMARY KEY  (`id`)
) ENGINE=InnoDB;

CREATE TABLE `B` (
    `id` int(10) unsigned NOT NULL auto_increment,
    `a_id` int(10) unsigned NOT NULL,
    PRIMARY KEY  (`id`),
    KEY `a_id` (`a_id`),
    CONSTRAINT `b_ibfk_1` FOREIGN KEY (`a_id`) REFERENCES `a` (`id`)
) ENGINE=InnoDB;

You can leave the column a_idin the table Busing the following command:

alter table B drop foreign key b_ibfk_1, drop column a_id;
+5
source

All Articles