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.