Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET Core new project not creating database by default

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

like image 635
Wakka Sakka Avatar asked Feb 06 '26 18:02

Wakka Sakka


1 Answers

If you want to create a database schema only, you may call:

//IDbContext context;
context.Database.EnsureCreated();

But note, that

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 use context.Database.Migrate() instead.

like image 70
Set Avatar answered Feb 09 '26 08:02

Set



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!