This has nothing to do with migrations at all.
The exception is telling you that you haven't configured your DbContext implementation with a database engine to use. Take a look at your code:
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (optionsBuilder.IsConfigured)
{
optionsBuilder.UseSqlServer("Server=DESKTOP-1M2N4KR\\EMMA;Database=Rocky;Integrated Security=true; Trusted_Connection=True;TrustServerCertificate=True;");
}
base.OnConfiguring(optionsBuilder);
}
Your code is checking to see if the options have already been configured. Hint: the options have NOT been configured! That's why you're getting the exception you're getting. Invert the conditional expression in the
if
statement and it should work:
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (!optionsBuilder.IsConfigured)
{
optionsBuilder.UseSqlServer("Server=DESKTOP-1M2N4KR\\EMMA;Database=Rocky;Integrated Security=true; Trusted_Connection=True;TrustServerCertificate=True;");
}
base.OnConfiguring(optionsBuilder);
}
Just a heads up. You could have figured this out in about 5 seconds using the debugger and stepping through the OnConfiguring code one line at a time to see what was happening.
I'm going to completely ignore the fact you're hard-coding the connection string in your code. That should be stored in a configuration file and your code should be written to grab the connection string from there.