2012-03-15 4 views
4

Add-Migrationで初期移行を作成しました。空のDBにUpdate-Databaseを実行すると、__MigrationHistoryテーブルにエントリを追加するなど、すべてのテーブルが作成されます。Entity Framework 4.3.1は常にUpdate-Databaseですべての移行を実行します

は今、私はちょうどテストするために、再びUpdate-Databaseを実行し、私はこれを取得「変更は検出されません」の代わりに:

PM> Update-Database -Verbose -Project testProject.Web 
Using StartUp project 'testProject.Web'. 
Target database is: 'testProject_dbo' (DataSource: localhost, Provider: Devart.Data.MySql, Origin: Explicit). 
Applying explicit migrations: [201203151243164_Start]. 
Applying explicit migration: 201203151243164_Start. 
CREATE TABLE attachments ( 
...table data... 
) 
Table 'attachments' already exists 
Table 'attachments' already exists 

更新が現在のDBの状態を認識していないように思え。唯一の解決策は、すべてのテーブルを削除して更新することです。それ以上の移行を追加しても機能します。

ご覧のとおり、別のデータベースプロバイダ(Devart.Data.Mysql)を使用していますが、問題があるかどうかはわかりません。たぶん私は何かが些細な行方不明ですか?

+0

これがデフォルトプロバイダのSQL Serverでも発生する場合は、検証できますか? –

+0

はい、\ SQLEXPRESSに接続するデフォルトのプロバイダで動作します。データベースを作成し、再度実行したとき:明示的な移行が保留されていません。 – ciscoheat

+0

このような場合は、さらに調査するためにDevartサポートに連絡してください。 –

答えて

3

DevArtと通信した後に問題が解決されました。私はEnable-Migrationsを実行したときに生成されたConfigurationクラスでIgnoreSchemaName回避策を呼び出さなかった。要約すると、これはそれが最終的に働かせたクラスです。その後

internal sealed class Configuration : DbMigrationsConfiguration<YourDbContext> 
{ 
    public Configuration() 
    { 
     // Because the Package Manager Console (NuGet) instantiates YourDbContext with the empty constructor, 
     // a custom connection must be specified. Based on http://www.devart.com/blogs/dotconnect/?p=5603 
     // Note that the MySqlProviderFactory must also be present in Web.config or App.config in the *startup project* 
     // for this to work! Configuration example: 

     /* 
      <system.data> 
      <DbProviderFactories> 
       <clear /> 
       <remove invariant="Devart.Data.MySql" /> 
       <add name="dotConnect for MySQL" invariant="Devart.Data.MySql" description="Devart dotConnect for MySQL" type="Devart.Data.MySql.MySqlProviderFactory, Devart.Data.MySql, Version=6.30.196.0, Culture=neutral, PublicKeyToken=09af7300eec23701" /> 
      </DbProviderFactories> 
      </system.data> 
     */ 

     // Apply the IgnoreSchemaName workaround 
     MySqlEntityProviderConfig.Instance.Workarounds.IgnoreSchemaName = true; 

     // Create a custom connection to specify the database and set a SQL generator for MySql. 
     var connectionInfo = MySqlConnectionInfo.CreateConnection("<Your ConnectionString>"); 

     TargetDatabase = connectionInfo; 
     SetSqlGenerator(connectionInfo.GetInvariantName(), new MySqlEntityMigrationSqlGenerator()); 

     // Enable automatic migrations if you like 
     AutomaticMigrationsEnabled = false; 

     // There is some problem with referencing EntityFramework 4.3.1.0 for me, so another fix that needs 
     // to be applied in Web.config is this: 

     /* 
      <runtime> 
      <assemblyBinding> 
       <!-- This redirection is needed for EntityFramework Migrations through the Package Manager Console (NuGet) --> 
       <dependentAssembly> 
       <assemblyIdentity name="EntityFramework" publicKeyToken="b77a5c561934e089" /> 
       <bindingRedirect oldVersion="4.3.0.0" newVersion="4.3.1.0" /> 
       </dependentAssembly> 
      </assemblyBinding> 
      </runtime> 
     */ 

     // After these Web.config additions, running migrations in Package Manager Console should be as easy as: 
     // Update-Database -Verbose -ProjectName Your.MigrationsProject 

     // Creating new migrations: 
     // Add-Migration -Name MigrationDescription -ProjectName Your.MigrationsProject 
    } 
} 

私は正しい移行履歴エントリを生成するために、データベース1つのより多くの時間を空にし、すべてが大丈夫でした。 DevArtは、設定の詳細を示します。

+0

ああ、ありがとう!それは私にとって非常に役に立ちました。 Fyi、コメントアウトされたweb.configフラグメントに、最初のassemblyBindingタグがありません。 – Jason

+0

ああ、どこに行ったのですか?まあ、今修正! – ciscoheat

1

私は同じような奇妙な振る舞いをしていましたが、私のケースでははるかに簡単でした。コードマージによって、マイグレーションを含むプロジェクトではないデフォルトに自分のスタートアッププロジェクトがリセットされました。

-Verboseフラグを試してみるまで私は気付きませんでした。これは、スタートアッププロジェクトがパッケージマネージャで設定されたNuGetプロジェクトと同じではないことを明示していました。

ワースの健全性チェック!

+0

私のためにそれを解決しました。私は、パッケージマネージャウィンドウの「デフォルトプロジェクト」がデフォルトプロジェクトが使用されていると思っていました。 – garethb

関連する問題