Entity framework - Unable to create an object of type <type>. For the different patterns supported at design time see <link>

Today I was trying to make an initial migration using Entity framework. I encountered an error when calling dotnet ef migrations add InitialCreate:

C:\Users\peter\source\repos\WebApplication\MyDbContext> dotnet ef migrations add InitialCreate
Build started...
Build succeeded.
Unable to create an object of type 'MyDbContext'. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728

The issue was that I had not declared a parameterless constructor:

public MyDbContext() { }

If you were trying to do a migration you could use the following in the empty constructor (UseSqlServer for MSSQL server):

optionsBuilder.UseSqlServer("ThisIsJustForMigrations");

When calling UseSqlServer you have provided a non-empty and not null string, but it does not have to be a connection string to a database that is reachable. It can use the previous snapshot to make the migration.

I hope this helps, feel free to leave a comment down below!