Fail to run Code-First Migration - RenameColumn - with MySql

Fail to run Code-First Migration - RenameColumn - with MySql

Postby mayash75 » Sun 03 Jun 2012 20:25

Not sure this is the right forum, but I'll try...

I have an issue which I could not find answer for across the web.

I am using CodeFirst EF 4.3.1 Migrations with MySQL.

My MySQL provider is Devart.

After running Add-Migration against an existing database, I got the following code:

public partial class ChangeSet_1231 : DbMigration
{
public override void Up()
{
RenameColumn(table: "RW_TTaskInstanceProperties", name: "TaskInstance_TaskInstanceId", newName: "TaskInstanceId");
}

public override void Down()
{
RenameColumn(table: "RW_TTaskInstanceProperties", name: "TaskInstanceId", newName: "TaskInstance_TaskInstanceId");
}
}


Running Update-Database results in the following error:

PM> Update-Database -verbose –startupprojectname "RTDataAccess"
Using NuGet project 'RTDataAccess'.
Target database is: 'rsruntime' (DataSource: localhost, Provider: Devart.Data.MySql, Origin: Explicit).
Applying explicit migrations: [201205311312361_ChangeSet_1231].
Applying explicit migration: 201205311312361_ChangeSet_1231.
ALTER TABLE RW_TTaskInstanceProperties RENAME COLUMN TaskInstance_TaskInstanceId TO TaskInstanceId
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'COLUMN TaskInstance_TaskInstanceId TO TaskInstanceId' at line 2


From looking at the error details I see that the RenameColumn is translated to a MsSql command, rather than MySql command, so no wonder it reports about a syntax error.

Any ideas how to solve it?

I know I can use Update-Database -script, then edit the script to fit MySql and run it, but I prefer to make the Update-Database command work...

Thanks.
mayash75
 
Posts: 2
Joined: Sun 03 Jun 2012 15:48

Re: Fail to run Code-First Migration - RenameColumn - with M

Postby Shalex » Tue 05 Jun 2012 06:39

Thank you for your report. We are investigating the issue.
Shalex
Devart Team
 
Posts: 7614
Joined: Thu 14 Aug 2008 12:44

Re: Fail to run Code-First Migration - RenameColumn - with M

Postby Shalex » Wed 06 Jun 2012 08:15

  • The MySqlRenameColumnConfiguration class is added for the possibility of setting column definition for the RenameColumn operation in Code-First Migrations.
  • The behaviour is changed: an exception is generated for the default RenameColumn operation which is without column definition in Code-First Migrations.
We will post here when the corresponding build of dotConnect for MySQL is available for download.
Shalex
Devart Team
 
Posts: 7614
Joined: Thu 14 Aug 2008 12:44

Re: Fail to run Code-First Migration - RenameColumn - with MySql

Postby Shalex » Fri 08 Jun 2012 16:00

New build of dotConnect for MySQL 7.0.17 is available for download!
It can be downloaded from http://www.devart.com/dotconnect/mysql/download.html (trial version) or from Registered Users' Area (for users with active subscription only).
For more information, please refer to http://forums.devart.com/viewtopic.php?f=2&t=24291 .

Here is an example of using the MySqlRenameColumnConfiguration class:
Code: Select all
RenameColumn(table: "test.dept", name: "deptno", newName: "deptnorenamed", anonymousArguments: new MySqlRenameColumnConfiguration() {  ColumnDefinition = "int" } );
Shalex
Devart Team
 
Posts: 7614
Joined: Thu 14 Aug 2008 12:44


Return to dotConnect for MySQL