2012-03-15 5 views
4

Add-Migration으로 초기 마이그레이션을 만들었습니다. 빈 DB에 Update-Database을 실행하면 __MigrationHistory 테이블에 항목을 추가하는 것을 포함하여 모든 테이블이 만들어집니다. Entity Framework 4.3.1은 항상 업데이트 데이터베이스에서 모든 마이그레이션을 실행합니다.

는 지금은 "감지 된 변화는"나는이를 얻을 다시 그냥 대신의 테스트 Update-Database을 실행하여 업데이트가 현재의 DB 상태의 인식처럼

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 

것 같다. 유일한 해결책은 모든 테이블을 삭제하고 업데이트하는 것입니다. 더 많은 마이그레이션을 추가 할 경우에도 작동합니다.

보시다시피 평소와 다른 데이터베이스 공급자 (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 
    } 
} 

, 모든 것이 좋았다. DevArt에는 구성에 대한 자세한 내용이 나와 있습니다.

+0

아, 고마워요! 그것은 나에게 매우 도움이되었다. Fyi, 주석 처리 된 web.config 부분에 assemblyBinding 태그가 없습니다. – Jason

+0

오, 그게 어디 갔지? 글쎄, 이제 고쳐! – ciscoheat

1

나는 이상한 행동을 보였지만 내 경우에는 훨씬 간단 해졌습니다. 코드 병합은 마이 그 레이션이 포함 된 프로젝트가 아닌 기본값으로 시작 프로젝트를 재설정했습니다.

-Verbose 플래그를 시도 할 때까지 알지 못했습니다.이 플래그는 패키지 관리자에서 구성한 NuGet 프로젝트와 동일하지 않습니다.

Worth the sanity check!

+0

해결되었습니다. 나는 패키지 관리자 윈도우의 '기본 프로젝트'가 기본 프로젝트 였다고 생각했지만 분명히 그렇지 않았습니다! – garethb