Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mysql error 150 on column rename

I've an old db with columns'charset to latin1

Now i'm trying to change the whole db in utf8, i've made a script to change all the tables in utf8 like this:

ALTER TABLE `mytable` CHARACTER SET utf8;

and all the columns like this:

ALTER TABLE `mytable` CHANGE `mycolumn` `mycolumn` varchar(200) CHARACTER SET utf8;

But on some columns (primary keys and constraints, i guess) i'm getting this error:

Error on rename of './test/#sql-5028_217b96' to './test/mytable' (errno: 150)

Anyone knows how to get around this?

like image 471
Cirou Avatar asked Oct 01 '12 12:10

Cirou


1 Answers

The most likely your mycolumn is a part of a foreign key. If so, you have to remove the constraint, then change type for the both primary/foreign key and then add constraint again.

like image 78
Maksym Polshcha Avatar answered Nov 06 '22 19:11

Maksym Polshcha