Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
260 views
in Technique[技术] by (71.8m points)

c# - Entity Framework Core project's migration fails and debug profile does not exist

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Based on your description, you want to create an Entity Framework Core migration.

I assumed that you use sqlserver.

You can refer to the following steps to create the EF Core migration.

First, please create an console app(.Net Core).

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();
    }
}

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

Package Manager Console

Finally, you can check the database design.

Dtabase Desighn


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...