'Migration not working

I have a project that uses .net core 2.0 with EntityFrameworkCore, Docker and SQL Server.

I can't get migrations to work. When I try Add-Migration InitialCreate I get the following error:

Startup project 'docker-compose' is a Docker project. Select an ASP.NET Core Web Application as your startup project and try again.

I don't even have a asp.net web application but just a .net core console program. How do I enable migrations?

If I change the startup project to the console application I get:

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



Solution 1:[1]

The answer to the error Startup project 'docker-compose' is a Docker project. Select an ASP.NET Core Web Application as your startup project and try again. Was to right click my actual code project in VisualStudio and click Set as Startup Project.

The solution file had marked the docker-compose project as the default project.

Solution 2:[2]

Add-Migration has optional parameters -StartupProject and -Project.

These allow you to specify alternatives to the solutions configured Startup Project and the currently selected project in Package Manager/Console

If the project you want the migrations to be created in is not actually your Startup project then using these parameters means you do not have to constantly change your solutions configuration every time you want to run a migration.

So the command would look like:

Add-Migration InitialCreate -StartupProject MyProjectName -Project MyProjectName

Solution 3:[3]

Another cause to:

Startup project 'docker-compose' is a Docker project. Select an ASP.NET Core Web Application as your startup project and try again.

can also be that your context is missing expected constructor signatures. You need those:

public SomeContext(DbContextOptions options) : base(options)
{
}

public SomeContext()
{
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Nick
Solution 2 kaykayman
Solution 3 Henrik