How do i add-migrations into a separate data project??
I've got two projects, a data project with the context and models in and the website project which will use it. I've linked the two together all fine and dandy, the problem is that when I try and add a migration to the data project with add-migration initialmigration
, the error
Unable to create an object of type 'myContext'. Add an implementation of 'IDesignTimeDbContextFactory' to the project, or see https://go.microsoft.com/fwlink/?linkid=851728 for additional patterns supported at design time.
The link has details on how to add the IDesignTimeDbContextFactory
but which doesn't work because UseSqlServer
doesn't exist as a command. That page does link to the updated version at https://docs.microsoft.com/en-us/aspnet/core/migration/1x-to-2x/#update-main-method-in-programcs which says to put code into program.cs
Even if I follow the instructions and add it to my data project (along with the associated references) so that I include
public class Program
{
public static void Main(string[] args)
{
BuildWebHost(args).Run();
}
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.Build();
}
which is what it says to do, but I get the same error message. So, regardless of whether I include the section of code or not I get the same error message, despite the Microsoft.com page stating that the above code stops the error message I'm getting from appearing.
I've tried putting the context and model into my main project and that generates migrations fine, so the code for those is fine at least.
How do i add-migrations into a separate data project??
Add-Migration
has a -Project
parameter.
Add-Migration -Project MyProject -Context MyDbContext -Name InitialMigration
EDIT: To see all options for a cmdlet (since Package Manager Console is just PowerShell) do
Get-Help Add-Migration -Full