gpt4 book ai didi

mysql - 无法从 Migration MySQL Ef-Core 生成数据库表

转载 作者:行者123 更新时间:2023-11-29 07:25:42 25 4
gpt4 key购买 nike

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

add-migration initial

Nuget Package Manager Console 中的命令选择Class Library ProjectMigration 文件在Class Library Project 中生成,这很好。

当我运行命令时

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

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

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

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

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

最佳答案

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

两个建议:

  1. 请考虑从项目中删除整个“迁移”(所有目录、文件等),然后重新运行 dotnet ef migrations add...,然后是 dotnet ef 数据库更新...

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

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

关于mysql - 无法从 Migration MySQL Ef-Core 生成数据库表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53928554/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com