I created new ASP.NET Core project with Identity Individual User
but it did not create any database.
I have to use add-migration
update-database
manually.
I remember, in the past, everything was done automatically. Dunno what's wrong this time.
VS2017.3
Depending on the version of dotnet core you have, ASP.NET core may not automatically create a database for you when you create a new app.
However, simply migrating and updating the database should work.
First, create a new migration with the syntax dotnet ef migrations add <MIGRATION_NAME>
. Like so
dotnet ef migrations add InitialMigration
and then you update the database like so
dotnet ef database update
.
This should do the trick.
If you want to create a database schema only, you may call:
//IDbContext context;
context.Database.EnsureCreated();
EnsureCreated
totally bypasses migrations and just creates the schema for you, you can't mix this with migrations.EnsureCreated
is designed for testing or rapid prototyping where you are ok with dropping and re-creating the database each time. If you are using migrations and want to have them automatically applied on app start, then you can usecontext.Database.Migrate()
instead.