简体   繁体   中英

Adding Entity Framework core migration without using other projects

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)?

I am not sure what you're trying to do but here are the DotNET EF Core commands to create migrations and database.

Command

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

Using a Separate Migrations Project

You may want to store your migrations in a different project than the one containing your DbContext. Then follow these MS Docs guidelines.

https://docs.microsoft.com/en-us/ef/core/managing-schemas/migrations/projects?tabs=dotnet-core-cli

我认为这是一个启动项目的要求

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM