实体框架核心项目的迁移失败,并且调试配置文件不存在 [英] Entity Framework Core project's migration fails and debug profile does not exist
问题描述
我尝试创建 Entity Framework Core
迁移,但是失败.这是Visual Studio 2019程序包管理器控制台的输出
I tried to create an Entity Framework Core
migration but it fails. This is the output from the Visual Studio 2019 Package manager console
> 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.
然后我尝试构建我的代码,并遇到以下问题:调试配置文件不存在
.我该如何解决这个问题?我已经尝试了一切,但似乎无法解决.
I then tried to build my code and got the following problem:
debug profile does not exist
. How do I fix this problem? I have tried everything and I just can't seem to solve it.
推荐答案
根据您的描述,您想要创建一个Entity Framework Core迁移.
Based on your description, you want to create an Entity Framework Core migration.
我假设您使用的是sqlserver.
I assumed that you use sqlserver.
您可以参考以下步骤来创建EF Core迁移.
You can refer to the following steps to create the EF Core migration.
首先,请创建一个控制台应用程序(.Net Core).
First, please create an console app(.Net Core).
第二,请安装以下nuget软件包:
Second,please install the following nuget packages:
- Microsoft.EntityFrameworkCore.SqlServer
- Microsoft.EntityFrameworkCore.Design
- Microsoft.EntityFrameworkCore.Tools
第三,请向您的控制台应用程序添加两个类.
Third, please add two classes to your console app.
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数据库的字符串.(请首先创建一个数据库)第三,您可以在程序包管理器"控制台中执行以下命令.
The Connectionstring is the string that you connect to sql server database.(please create a database first) Third, you can execute the following command in the Package manager console.
PM> Add-Migration Initial
PM> Update-Database
最后,您可以检查数据库设计.
Finally, you can check the database design.
这篇关于实体框架核心项目的迁移失败,并且调试配置文件不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!