Code First Migrations: MoveTableOperation is not supported.

Discussion of open issues, suggestions and bugs regarding Entity Framework support in ADO.NET Data providers
Post Reply
moxitose
Posts: 2
Joined: Wed 01 Feb 2012 17:27

Code First Migrations: MoveTableOperation is not supported.

Post by moxitose » Wed 01 Feb 2012 17:33

I'm currently experimenting with Code First Migrations support for Devart but can't seem to get it working...

1.) I've added a migration that adds a table

Code: Select all

 public override void Up()
        {
			CreateTable(
			   "S398_COMPANY",
			   c => new
			   {
				   CompanyId = c.Int(nullable: false, identity: true),
				   Name = c.String(),
			   })
			   .PrimaryKey(t => t.CompanyId);
        }
2.) My Configuration is setup like this:

Code: Select all

  internal sealed class Configuration : DbMigrationsConfiguration
    {
        public Configuration()
        {
            AutomaticMigrationsEnabled = true;
			SetSqlGenerator("Devart.Data.Oracle", new OracleEntityMigrationSqlGenerator());
        	ContextType = typeof (Context);
        }

        protected override void Seed(ConsoleApplication3.Context context)
        {
        }
    }

==> The error that I get: MoveTableOperation is not supported.

Code: Select all

Update-Database -Script
Applying explicit migrations: [201202011544015_Initial].
Applying explicit migration: 201202011544015_Initial.
Applying automatic migration: 201202011722453_AutomaticMigration.
System.NotSupportedException: MoveTableOperation is not supported.
   at Devart.Common.Entity.Migrations.a.a(MoveTableOperation A_0)
   at Devart.Common.Entity.Migrations.a.a(MigrationOperation A_0)
   at Devart.Common.Entity.Migrations.a.a(IEnumerable`1 A_0)
   at Devart.Common.Entity.Migrations.c.a(IEnumerable`1 A_0, String A_1)
   at Devart.Data.Oracle.Entity.Migrations.OracleEntityMigrationSqlGenerator.Generate(IEnumerable`1 migrationOperations, String providerManifestToken)
   at System.Data.Entity.Migrations.DbMigrator.ExecuteOperations(String migrationId, XDocument targetModel, IEnumerable`1 operations, Boolean downgrading)
   at System.Data.Entity.Migrations.DbMigrator.AutoMigrate(String migrationId, XDocument sourceModel, XDocument targetModel, Boolean downgrading)
   at System.Data.Entity.Migrations.Infrastructure.MigratorLoggingDecorator.AutoMigrate(String migrationId, XDocument sourceModel, XDocument targetModel, Boolean downgrading)
   at System.Data.Entity.Migrations.Infrastructure.MigratorBase.AutoMigrate(String migrationId, XDocument sourceModel, XDocument targetModel, Boolean downgrading)
   at System.Data.Entity.Migrations.DbMigrator.Upgrade(IEnumerable`1 pendingMigrations, String targetMigrationId, String lastMigrationId)
   at System.Data.Entity.Migrations.Infrastructure.MigratorLoggingDecorator.Upgrade(IEnumerable`1 pendingMigrations, String targetMigrationId, String lastMigrationId)
   at System.Data.Entity.Migrations.Infrastructure.MigratorBase.Upgrade(IEnumerable`1 pendingMigrations, String targetMigrationId, String lastMigrationId)
   at System.Data.Entity.Migrations.Infrastructure.MigratorScriptingDecorator.ScriptUpdate(String sourceMigration, String targetMigration)
   at System.Data.Entity.Migrations.Design.ToolingFacade.ScriptUpdateRunner.RunCore()
   at System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.Run()
MoveTableOperation is not supported.

Is Code First Migrations really supported or am I doing something stupid? Thanks for any help!!!

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Post by Shalex » Tue 07 Feb 2012 16:39

You have turned on automatic migrations (AutomaticMigrationsEnabled = true;). That's why automatically computed migration will be used when executing Update-Database without specifying a migration name. And it seems like EF code-first migration engine decided that MoveTableOperation has to be executed. But the MoveTable operation is not supported in dotConnect providers because of a necessity of using an IgnoreSchemaName workaround when working with EF Code-First Migrations. Perhaps, we will investigate the possibility of supporting the MoveTableOperation feature after EF Code-First Migrations is released.

If you turn off automatic migrations:

Code: Select all

AutomaticMigrationsEnabled = false;
and execute:

Code: Select all

Update-Database -Script -TargetMigration:"Your_migration_class_name"
then the code will work.

rmagruder
Posts: 47
Joined: Thu 26 Jun 2014 17:12

Re: Code First Migrations: MoveTableOperation is not supported.

Post by rmagruder » Tue 29 Jul 2014 17:52

Did this ever get implemented?

I need to move some experimental tables from my schema to the MASTER Schema on Oracle and I'm getting the same error.

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Re: Code First Migrations: MoveTableOperation is not supported.

Post by Shalex » Wed 30 Jul 2014 07:57

Please pay attention to our comments in the previous message concerning usage of AutomaticMigrationsEnabled. If this doesn't help, send us a small test project and specify the exact steps we should follow in our environment to reproduce the problem.

rmagruder
Posts: 47
Joined: Thu 26 Jun 2014 17:12

Re: Code First Migrations: MoveTableOperation is not supported.

Post by rmagruder » Wed 30 Jul 2014 13:24

I have never used Automatic Migrations. I altered the SCHEMA to go from my private schema to the MASTER Schema in Data Annotations, and then issued add-migration and update-database. It created a script with two MoveTable() operations and failed on the update-database.

Could it be the nature of the move? (changing schema?)

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Re: Code First Migrations: MoveTableOperation is not supported.

Post by Shalex » Tue 05 Aug 2014 16:34

dotConnect for Oracle doesn't support MoveTableOperation because there is no "acceptable" way in Oracle server itself to support this operation (usually it assumes copying table/data without taking into account relations, etc).

As a workaround, we recommend you to replace MoveTable() with Sql() operation(s) which will include the needed DDL.

Vivian
Posts: 2
Joined: Mon 23 Feb 2015 15:09

Re: Code First Migrations: MoveTableOperation is not supported.

Post by Vivian » Mon 23 Feb 2015 15:15

Hi Shalex!,
I read the entire post, because I have the same problem. You answer "As a workaround, we recommend you to replace MoveTable() with Sql() operation(s) which will include the needed DDL."
But, MoveTable is an automatic action when the migrations occurs, How I supposed what is the sql command? Do you have some example to replace MoveTable on migration's code? It's my first time with migrations. :oops:

Thanks!!!

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Re: Code First Migrations: MoveTableOperation is not supported.

Post by Shalex » Thu 26 Feb 2015 14:51

Here is an example of the Sql() operation:

Code: Select all

public partial class AddPostAbstract : DbMigration 
    { 
        public override void Up() 
        { 
             Sql("your SQL here for droping table in schema A and recreating it in schema B"); 
        }
[...]
This workaround can be applied only with the “AutomaticMigrationsEnabled = false;” approach because it assumes that a user will write SQL manually.

Vivian
Posts: 2
Joined: Mon 23 Feb 2015 15:09

Re: Code First Migrations: MoveTableOperation is not supported.

Post by Vivian » Thu 26 Feb 2015 15:17

Thanks for your reply, I will recreate this solution and I hope that works.

Gruffta
Posts: 11
Joined: Tue 11 Aug 2009 14:39

Re: Code First Migrations: MoveTableOperation is not supported.

Post by Gruffta » Fri 21 Oct 2016 09:36

Maybe a bit late but I had the same issue today.

I have 2 contexts both using migrations, when running update-database for the first time on the second context you will get this error as it retries to create the __MigrationsHistory table when it should just insert the context data as a row if this exists.

As the table contains a context type field and and records are retrieved from this table passing the context type in I would say this is probably a bug and you should check for existence of the migrations history table in the schema first.

To workaround this issue you can just run the migration command with the -Script setting and remove the create statement for the migrations history table.

Thanks
Gareth

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Re: Code First Migrations: MoveTableOperation is not supported.

Post by Shalex » Wed 26 Oct 2016 13:41

Gruffta wrote:I have 2 contexts both using migrations, when running update-database for the first time on the second context you will get this error as it retries to create the __MigrationsHistory table when it should just insert the context data as a row if this exists.
Thank you for your report. We will investigate the issue and notify you about the result.

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Re: Code First Migrations: MoveTableOperation is not supported.

Post by Shalex » Fri 09 Dec 2016 18:55

The bug with creating database objects in the same schema by several EF6 contexts in Code-First approach is fixed: viewtopic.php?f=1&t=34692.

Post Reply