简体   繁体   中英

Entity Framework code first migrations with multiple databases

I have an ASP.NET MVC application with Owin.Security authentication. As you know visual studio creates a class inheriting IdentityDbContext for handling my application's user database. Besides that I needed to read/write some data from another database so I created another dbContext using code first model and worked with it for a while and everything was fine.

Today I needed to make a modification to IdentityDbContext so I made some changes in the class files and added some new tables. The problem is that now when I call add-migration in package manager console a migration is created with empty Up and Down methods. I think the problem is with my application having multiple dbcontexts.

因此,您可以将-Context参数用于 Add-Migration 命令

Add-Migration [-Name] <String> [-OutputDir <String>] [-Context <String>] [-Project <String>] [-StartupProject <String>] [-Environment <String>] [<CommonParameters>]

In case someone faces the same problem in the future, what finally solved my problem was excluding old files in Migrations folder from my project and call Enable-migrations -Force -ContextTypeName MySampleContext with MySampleContext being the context that I want to add migrations for. In case I need my old migrations in the future I still have the files and I can include them in my project again.

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