没有应用迁移。该数据库已经是最新的。完成

时间:2019-06-21 11:36:06

标签: entity-framework .net-core ef-migrations

我有一些模型:

enter image description here

我已经运行了添加迁移命令

dotnet ef migrations add <migration name>

现在我设置了以下迁移:

enter image description here

当我启动dotnet ef database update时,我看到我的表是SQL客户端,并且一切正常。

当我连接到另一个数据库时,问题开始了。我想将迁移应用到新数据库。但是,当我运行dotnet ef database update时,会看到No migrations were applied. The database is already up to date. Done.消息。该命令仅创建__EFMigrationsHistory表,并且该表为空。如何在新数据库上使用迁移?

这是我的ApplicationContext

public class ApplicationContext : DbContext
{
    private readonly string _connectionString;

    public ApplicationContext(IConfiguration configuration)
    {
        _connectionString = configuration.GetConnectionString("Recipes");
    }

    public DbSet<User> Users { get; set; }
    public DbSet<Recipe> Recipes { get; set; }
    public DbSet<RecipeStep> RecipeSteps { get; set; }
    public DbSet<Ingredient> Ingridients { get; set; }
    public DbSet<Category> Categories { get; set; }
    public DbSet<Advertising> Advertisings { get; set; }
    public DbSet<FileModel> Files { get; set; }
    public DbSet<RecipeLike> RecipeLikes { get; set; }
    public DbSet<RecipeDislike> RecipeDislikes { get; set; }
    public DbSet<Bookmark> Bookmarks { get; set; }
    public DbSet<Purchase> Purchases { get; set; }

    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
    {
        optionsBuilder.UseNpgsql(_connectionString);
    }
}

和appsettings.json

{
  "ConnectionStrings": {
    "Recipes" : "connection string is here"
  },
  "Logging": {
    "LogLevel": {
      "Default": "Debug",
      "System": "Information",
      "Microsoft": "Information"
    }
  }
}

1 个答案:

答案 0 :(得分:0)

好的,我已经为我的案件解决了。是.Designer.cs个文件,我丢失了。

如果丢失,您将遇到同样的问题

enter image description here