我有一些模型:
我已经运行了添加迁移命令
dotnet ef migrations add <migration name>
现在我设置了以下迁移:
当我启动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"
}
}
}