Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error renaming a column in MySQL

How do I rename a column in table xyz? The columns are:

Manufacurerid, name, status, AI, PK, int 

I want to rename to manufacturerid

I tried using PHPMyAdmin panel, but I get this error:

MySQL said: Documentation #1025 - Error on rename of '.\shopping\#sql-c98_26' to '.\shopping\tblmanufacturer' (errno: 150) 
like image 594
Bharanikumar Avatar asked Oct 23 '10 03:10

Bharanikumar


People also ask

How do I rename a column in MySQL?

Rename MySQL Column with the CHANGE Statement Enter the following command in your MySQL client shell to change the name of the column and its definition: ALTER TABLE table_name CHANGE old_column_name new_col_name Data Type; You can change the data type of the column or keep the existing one.


1 Answers

Lone Ranger is very close... in fact, you also need to specify the datatype of the renamed column. For example:

ALTER TABLE `xyz` CHANGE `manufacurerid` `manufacturerid` INT; 

Remember :

  • Replace INT with whatever your column data type is (REQUIRED)
  • Tilde/ Backtick (`) is optional
like image 169
Matt Diamond Avatar answered Oct 08 '22 16:10

Matt Diamond