无法从迁移 MySQL Ef-Core 生成数据库表

Unable to generate database tables from Migration MySQL Ef-Core

我正在尝试使用 EF Core 迁移生成数据库和表。我有一个 Class 图书馆项目,其中包含所有必要的实体和迁移数据。我在另一个 ASP.NET Core 2.1 Web 应用程序中引用 Class 图书馆项目。 当运行宁

add-migration initial

Nuget 包管理器控制台中的命令选择 Class 库项目迁移 文件在 中生成Class 图书馆项目 很好。

当我运行命令

update-database

同时选择 class libaryweb project,我收到消息指出:

No migrations were applied. The database is already up to date.

我的DbContextClass:

 public class UserDbContext:DbContext
    {
        public UserDbContext(DbContextOptions<UserDbContext> options) : base(options){}
        public DbSet<LoginSession> login_sessions { get; set; }
        public DbSet<Authentication> authentications { get; set; }
        public DbSet<RolePermissionMap> role_permission_maps { get; set; }
        public DbSet<Entity.User> users { get; set; }
        public DbSet<Role> roles { get; set; }
        public DbSet<UserRole> user_roles { get; set; }
    }

我试过了运行宁

dotnet ef database update

来自控制台的命令选择 Class 库项目,我收到一条错误消息:

The specified framework version '2.1' could not be parsed The specified framework 'Microsoft.NETCore.App', version '2.1' was not found.

当我将所有重要文件从 Class 库复制到另一个 Web 应用程序项目时,即迁移文件和 Web 项目在同一个文件中,一切正常。

我想知道当 class 库和 Web 应用程序位于不同的文件中时为什么会出现该错误并且无法找到解决方案。谁能帮我?我在 Web 应用程序中引用了许多 class 库。因此,我无法将所有必要的文件移植到另一个 Web 应用程序来生成数据库表。

我以前 运行 遇到过类似的问题。

两条建议:

  1. 请考虑从项目中删除整个 "Migration"(所有目录、文件等),然后重新 运行ning dotnet ef migrations add...,然后 dotnet ef database update...

  2. 考虑使用 Pomelo 数据提供程序 MySQL:

https://www.nuget.org/packages/Pomelo.EntityFrameworkCore.MySql