如何在Web API Core 1.1的.NET Core库项目中添加迁移 [英] How to add migration in .NET Core Library project in web API core 1.1

查看:107
本文介绍了如何在Web API Core 1.1的.NET Core库项目中添加迁移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

.net核心是我的新手。我在Web API核心1.1的.net核心Liabrary项目中添加了迁移。使用以下代码。

I am new in .net core. I am adding migration in .net core Liabrary project in web API core 1.1. using below code.

Add-Migration example1

但是它显示以下错误:

But it's showing below error:

推荐答案

如果您使用的是VS Code或其他编辑器:

在dotnet命令cli中输入:

dotnet ef迁移添加InitialCreate

In dotnet command cli type:
dotnet ef migrations add InitialCreate

obs:InitialCreate是迁移的名称,您可以指定任何名称。

obs:InitialCreate is the name of migration, you can give any name.

如果您使用的是Visual Studio:

创建数据库

一旦有了模型,就可以使用迁移创建数据库。

打开PMC:

工具-> NuGet软件包管理器->软件包管理器控制台

运行添加-迁移InitialCreate 以支持迁移以为模型创建初始表集。
如果在启动时收到错误,则无法将术语 add-migration识别为cmdlet的名称,请关闭并重新打开Visual Studio。
运行Update-Database以将新迁移应用于数据库。此命令在应用迁移之前创建数据库。

If you are using Visual Studio:
Create your database
Once you have a model, you can use migrations to create a database.
Open the PMC:
Tools –> NuGet Package Manager –> Package Manager Console
Run Add-Migration InitialCreate to scaffold a migration to create the initial set of tables for your model.
If you receive an error starting The term 'add-migration' is not recognized as the name of a cmdlet, close and reopen Visual Studio. Run Update-Database to apply the new migration to the database. This command creates the database before applying migrations.

来源: > https://docs.microsoft.com/zh-cn/ef/core/get-started/aspnetcore/new-db

这篇关于如何在Web API Core 1.1的.NET Core库项目中添加迁移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆