TheBadgerEB
TheBadgerEB

Reputation: 513

Entity Framework / ASP net core 2.0 - add migration working for some context but not for others

I created three of my contexts for my api on asp net core 1.0, then I changed over to 2.0. After changing over I needed to create my db and tables in a new instance of sql server. I updated the db with entity framework and everything worked as expected. Now I have created a fourth context using the same pattern as the other three (it's basically a carbon copy of one of the existing except for the pocos) and I'm getting this error message:

Unable to create an object of type 'MyFourthContext'. Add an implementation of 'IDesignTimeDbContextFactory < MyFourthContext >' to the project, or see https://go.microsoft.com/fwlink/?linkid=851728 for additional patterns supported at design time.

I have since updated one of my existing contexts and updated the db with no errors.

Is there some config I am missing, something that was created in asp net core 1.0 that I need to update? I've seen all the posts suggesting, like the error message states, to implement IDesignTimeDBContextFactory but that seems little hacky and doesn't feel right seeing as I can get my other contexts to work with no issues. I have also followed the steps in this link as others have suggested.

So I guess, to sum up I have two questions:

  1. Why does add-migration work for older contexts and not for new ones.
  2. How can I add a new migration without implementing anything I don't need.

Thanks in advance for any help!

Upvotes: 1

Views: 82

Answers (1)

TheBadgerEB
TheBadgerEB

Reputation: 513

Solved this one myself. It had been a while since I created the original contexts, I just needed to add a new service declaration in Startup.ConfigureServices().

Just thought I'd answer the question in case anyone else comes across the same issue.

Upvotes: 1

Related Questions