C# 不更新数据库';不创建表
我有5个SQL表,是用实体框架创建的。 但它不再创建表 我的背景:C# 不更新数据库';不创建表,c#,entity-framework,entity-framework-migrations,C#,Entity Framework,Entity Framework Migrations,我有5个SQL表,是用实体框架创建的。 但它不再创建表 我的背景: public class PlakappContext:DbContext { public DbSet<UserModel> User { get; set; } public DbSet<PostModel> Post { get; set; } public DbSet<PlateModel> Plate { get; set; }
public class PlakappContext:DbContext
{
public DbSet<UserModel> User { get; set; }
public DbSet<PostModel> Post { get; set; }
public DbSet<PlateModel> Plate { get; set; }
public DbSet<PostPlateModel> PostPlate { get; set; }
public DbSet<PostImageModel> PostImage { get; set; }
public DbSet<PostVoteModel> PostVote { get; set; }
}
我创建了所有的表,但无法为PostVote
创建
另外PostVoteModel
:
public class PostVoteModel
{
[Key]
public int VoteId { get; set; }
public int VoteStatus { get; set; }
public int PostId { get; set; }
public int UserId { get; set; }
public DateTime RegistrationDate { get; set; }
}
更新:
Migration.cs:
public partial class Initial : DbMigration
{
public override void Up()
{
}
public override void Down()
{
}
}
internal sealed class Configuration :
DbMigrationsConfiguration<Plakapp.Data.PlakappContext>
{
public Configuration()
{
AutomaticMigrationsEnabled = true;
}
protected override void Seed(Plakapp.Data.PlakappContext context)
{
// This method will be called after migrating to the latest version.
// You can use the DbSet<T>.AddOrUpdate() helper extension method
// to avoid creating duplicate seed data.
}
}
Configuration.cs:
public partial class Initial : DbMigration
{
public override void Up()
{
}
public override void Down()
{
}
}
internal sealed class Configuration :
DbMigrationsConfiguration<Plakapp.Data.PlakappContext>
{
public Configuration()
{
AutomaticMigrationsEnabled = true;
}
protected override void Seed(Plakapp.Data.PlakappContext context)
{
// This method will be called after migrating to the latest version.
// You can use the DbSet<T>.AddOrUpdate() helper extension method
// to avoid creating duplicate seed data.
}
}
内部密封类配置:
DBMigrations配置
{
公共配置()
{
AutomaticMiggerationsEnabled=真;
}
受保护的覆盖无效种子(Plakapp.Data.PlakappContext上下文)
{
//迁移到最新版本后将调用此方法。
//您可以使用DbSet.AddOrUpdate()助手扩展方法
//避免创建重复的种子数据。
}
}
确切的错误是什么?@johnyingi我没有收到任何错误。更新数据库命令正在工作。因此,它返回了“Running seed method”。但它没有在SQL中创建表。您可以向我们展示您的Configuration.cs
和Migration
文件吗。另外,一些工具需要编译代码来检测新的迁移。您可以尝试构建应用程序,然后运行更新数据库
命令。是否有PostVoteModel的迁移?@AdemCatamak我添加了configuration.cs和123_Initial.cs