Home > Enterprise >  EF Core cannot creating Database
EF Core cannot creating Database

Time:12-07

I want to create database with code first technique using EF 3.1. However, no matter what I try in EF 6.0, the database enter image description hereis not created.

CodePudding user response:

At first you need to create migration files with command dotnet ef migrations add Initial

Then you can manually create a new empty database Adatech. Or, if the specific case is to create database automatically during migration, you can add your own new migration (or modify Initial one, after it is created) and put there SQL CREATE DATABASE command there. (Don't forget to complement this by a rollback logic in Down() method)

Then apply this migration to your db: dotnet ef database update

Context itself doesn't do anything with your database, it is just a model of your database entities in scope of your application. Model that contains rules how this these entities should correlate with db.

More here https://docs.microsoft.com/en-us/aspnet/core/data/ef-mvc/migrations?view=aspnetcore-3.1

  • Related