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

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

问题描述

我是 .net 核心的新手.我正在 Web API 核心 1.1 中的 .net 核心库项目中添加迁移.使用下面的代码.

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

但它显示以下错误:

推荐答案

如果您使用的是 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 包管理器 –> 包管理器控制台
运行 Add-Migration 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/en-us/ef/core/get-started/aspnetcore/new-db

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

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