Bug #71102 Unknown column 'no' in 'field list' in MySql.Data.Entity Migration column rename
Submitted: 6 Dec 2013 11:22 Modified: 30 Dec 2013 22:27
Reporter: Stubby Manliness Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / NET Severity:S3 (Non-critical)
Version:>=6.7.4 OS:Windows
Assigned to: Roberto Ezequiel Garcia Ballesteros CPU Architecture:Any
Tags: .net Connector, column rename, migration, unknow column

[6 Dec 2013 11:22] Stubby Manliness
Description:
Hello,

My last migration only have one line:

RenameColumn(table: "cartline", name: "Promotion_PromotionId", newName: "PromotionId");
Then generate the following mysql code after apply Update-Database -Verbose:

set @columnType := (select case lower(IS_NULLABLE) when `no` then CONCAT(column_type, ` ` , `not null `)  when `yes` then column_type end from information_schema.columns where table_name = `cartline` and column_name = `Promotion_PromotionId` );
set @sqlstmt := (select concat(`alter table cartline change `Promotion_PromotionId` PromotionId` , @columnType));
prepare stmt @sqlstmt;
execute stmt;
deallocate prepare stmt
And throws a Unknown column 'no' in 'field list' error.

I Copypasted the first mysql sentence in PhpMyAdmin and get the same error.

How to repeat:
...

Suggested fix:
I found the code that makes it at the MySql.Data.Entity/MySqlMigrationSqlGenerator.cs

at

protected virtual MigrationStatement Generate(RenameColumnOperation op)

in line: 

sb.Append("set @columnType := (select case lower(IS_NULLABLE) when `no` then CONCAT(column_type, ` ` , `not null `)  when `yes` then column_type end from information_schema.columns where table_name = `" + TrimSchemaPrefix(op.Table) + "` and column_name = `" + op.Name + "` );");

may be (tested only in MySql, translated without test in c#):

sb.Append("set @columnType := (select case lower(IS_NULLABLE) when 'no' then CONCAT(`COLUMN_TYPE`, ' ' , 'not null ')  when 'yes' then `COLUMN_TYPE` end from information_schema.columns where `TABLE_NAME` = '" + TrimSchemaPrefix(op.Table) + "' and `COLUMN_NAME` = '" + op.Name + "' );");

Wish this helps. Thank you for your answer.
[30 Dec 2013 22:27] Daniel So
Added the following entry to the Connector/Net 6.6.7, 6.7.5, and 6.8.3 changelogs:

'The RenameColumn operation in an Entity Framework migration threw an “Unknown column 'no' in the 'field list'” error when Update-Database was applied.'