Reputation: 2687
In the new ASP.NET Core RC2 template (With no database available at the back-end), when I try to register a user it throws the following error for adding Migrations.
While in the past, it use to generate the database for us without adding initial migration when we run the application. Is there a way to create the database in ASP.NET Core RC2 without Initial Migration?
Upvotes: 0
Views: 727
Reputation: 64141
For testing scenario you can use context.Database.EnsureCreatedAsync()
somewhere during startup. Ensure you are using this pattern (for now) and not inject it directly in configure, to avoid issues during startup.
For future reference the code section copied from the MusicStore example application.
using (var serviceScope = serviceProvider.GetRequiredService<IServiceScopeFactory>().CreateScope())
{
var db = serviceScope.ServiceProvider.GetService<MusicStoreContext>();
if (await db.Database.EnsureCreatedAsync())
{
await InsertTestData(serviceProvider);
if (createUsers)
{
await CreateAdminUser(serviceProvider);
}
}
}
because at this point, there is no scope yet. If you later want to apply the migrations you can use context.Database.AsRelational().ApplyMigrations()
(GitHub issue)
Upvotes: 1