简体   繁体   中英

Entity Framework 6 Update-Database fails for migration created with -IgnoreChanges

I'm trying to create a DbContext specific to may Domain that has one model class entirely managed by EF, and another that gets mapped to a database view. To ensure EF doesn't try to create this view that already exists, I added just the view to my DbContext and ran the following command:

Add-Migration InitialUnmanaged -IngoreChanges

This creates a Migration with an empty Up and Down, which is exactly what I want. I'm able to update my dev database using this Migration, but whenever I try to add a second Migration that includes my EF-managed model class, I get an error.

Add-Migration Initial

Unable to generate an explicit migration because the following explicit migrations are pending: [201510151553565_InitialUnmanaged]. Apply the pending explicit migrations before attempting to generate a new explicit migration.

The thing is, I've already applied that explicit Migration, and I can see it in my MigrationHistory table.

MigrationId

201510151553565_InitialUnmanaged

Can anyone help me understand why this is happening and how to work around it?

I figured this out.

When I applied the Migration, it put the Migration History table in the same default schema as the model. However, when I tried to roll it back, it was looking for the Migration History in the connected user's schema. Since it wasn't there, it thought the database was at version 0.

I created an OracleDbConfiguration class to specify a custom HistoryContext that specifies the default schema for the Migration History table and I'm able to rollback as expected after applying a Migration.

I verified that I was able to recreate my initial steps and have them work as expected now that I'm explicitly specifying the schema for the Migration History table.

Either delete the migration or just run Update-Database to put entity back in sync. If it is an empty migration your database will not change.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM