Reputation: 363
When I create ORM model project with Entity Framework Core, I encounter problem with migrations. I usually start my project with data layer then generate my data model. After that I add migration independently (from other projects). How can I do add first migration using commands only, without configuring migration on other project or making it an executable project (like console)?
Upvotes: 6
Views: 6632
Reputation: 552
I am not sure what you're trying to do but here are the DotNET EF Core commands to create migrations and database.
First command is to install the EF Core migration tools.
dotnet tool install --global dotnet-ef --version 3.1.0
The Second command can be used to create a migration.
dotnet-ef migrations add First --project YourProject
The third one to create the database in SQL Server. The database will be created in the SQL server instance which is specified in the connection string inside appsettings.json.
dotnet-ef database update --project YourProject
You may want to store your migrations in a different project than the one containing your DbContext. Then follow these MS Docs guidelines.
https://learn.microsoft.com/en-us/ef/core/managing-schemas/migrations/projects?tabs=dotnet-core-cli
Upvotes: 3