-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
EF fails to add "Initial" migration #28280
Comments
@ScottKane Nothing obvious. If you run the EF application and use |
@ajcvickers Using EnsureCreated the app starts fine and the DB is successfully created, seems to just be an issue with migrations. |
Looking at following part in exception message
The application startup seems to be seeding database which is running a query against a database which doesn't exist. So through hosting context creation is supposed to throw this exception. But last line indicates that there is no other way that we could find to create context. Likely bad code in startup. |
Ok I've disabled the seeder for now but adding the migration now just runs the application which doesn't result in a migration being scaffolded:
I'm using the following style startup code: internal static class Program
{
private static IConfiguration _configuration = null!;
private static async Task Main() =>
await WebHost.CreateDefaultBuilder()
.UseStaticWebAssets()
.ConfigureAppConfiguration((_, configuration) => _configuration = configuration.Build())
.ConfigureServices(services =>
{
services.AddDbContext<ApplicationContext>(options => options.UseSqlServer(_configuration.GetConnectionString("DefaultConnection")));
services
.AddSingleton<IAuthorizationPolicyProvider, PermissionPolicyProvider>()
.AddScoped<IAuthorizationHandler, PermissionAuthorizationHandler>()
.AddIdentity<ApplicationUser, ApplicationRole>(
options =>
{
options.Password.RequiredLength = 6;
options.Password.RequireDigit = false;
options.Password.RequireLowercase = false;
options.Password.RequireNonAlphanumeric = false;
options.Password.RequireUppercase = false;
options.User.RequireUniqueEmail = true;
})
.AddEntityFrameworkStores<ApplicationContext>()
.AddDefaultTokenProviders();
})
.Configure((_, app) =>
{
app.Use...
})
.Build()
.RunAsync();
} |
My other application uses the UseStartup approach and never had this happen while creating a migration but I can't imagine that is the issue here |
Or is this because I had used EnsureCreated and I now need to delete that DB? |
This. The database already exist then error is not thrown and startup would work fine. |
I just tried deleting the DB and running the migration again but it just starts the application and doesn't scaffold the migration |
This is likely the issue. See #28105 /cc @davidfowl |
@ajcvickers That issue mentions that switching to |
Full verbose logs in case it's helpful:
|
I can confirm that after switching to |
Duplicate of #28105 |
I'm adding an initial migration to a new application, EF fails stating it can't connect to the database using the following connection string:
This DB context and configuration was migrated from an existing app which works fine.
I noticed part of the error mentions
Login failed for user 'SCOTTS-PC\scott'.
however this is the same credential used in another app to access a localdb which works fine. Am I missing something obvious here?EF Core version: 6.0.6
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: NET 6.0
Operating system: Windows 11
IDE: Rider 2022.1.2
The text was updated successfully, but these errors were encountered: