c# - Entity Framework Core 项目迁移失败,调试配置文件不存在
问题描述
我试图创建一个Entity Framework Core
迁移,但它失败了。这是 Visual Studio 2019 包管理器控制台的输出
> Each package is licensed to you by its owner. NuGet is not responsible for, nor does it grant any licenses to, third-party packages. Some packages may include dependencies that are governed by additional licenses. Follow the package source (feed) URL to determine any dependencies.
>
> Package Manager Console Host Version 5.7.0.6726
>
> Type 'get-help NuGet' to see all available NuGet commands.
PM> Add-Migration InitialCreate
> Build started...
> Build failed.
然后我尝试构建我的代码并遇到以下问题
debug profile does not exist
:我该如何解决这个问题?我已经尝试了一切,但我似乎无法解决它。
解决方案
根据您的描述,您希望创建 Entity Framework Core 迁移。
我假设你使用 sqlserver。
您可以参考以下步骤来创建 EF Core 迁移。
首先,请创建一个控制台应用程序(.Net Core)。
其次,请安装以下nuget包:
- Microsoft.EntityFrameworkCore.SqlServer
- Microsoft.EntityFrameworkCore.Design
- Microsoft.EntityFrameworkCore.Tools
第三,请在您的控制台应用程序中添加两个类。
public class Teacher
{
public int TeaID { get; set; }
public int Age { get; set; }
public string Name { get; set; }
}
public class TeaContext : DbContext
{
public DbSet<Teacher> Teachers { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder
.UseSqlServer(@"Connectionstring");
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Teacher>()
.HasNoKey();
}
}
Connectionstring 是你连接到sql server 数据库的字符串。(请先创建一个数据库) 第三,你可以在包管理器控制台中执行以下命令。
PM> Add-Migration Initial
PM> Update-Database
最后,您可以检查数据库设计。
推荐阅读
- java - 确定 Java 程序中 GDI 对象数量的最佳方法是什么?
- flutter - 如何在颤振中自定义小部件
- scala - 使用 scala 从 IntelliJ 连接到 Azure CosmosDB 时无法绕过代理
- java - 构造两个字符的模式(例如:“aabba”、“aba”)
- view - 如何为两个模型创建一个控制器?
- ansible - Ansible remote_user:root,ssh:权限被拒绝(公钥)
- reactjs - 带有 Reactjs 的 Botframework 不适用于 IE11
- angular - How to fix this angular error "Module build failed (from ./node_modules/sass-loader/lib/loader.js):"?
- java - 带有选项卡的 Activity 中的布局刷新问题
- c# - 我正在尝试使用 c# 从 Twitter api 获取请求令牌,但收到 400 错误请求错误