Update-Database不会创建表

时间:2018-04-08 20:03:05

标签: c# entity-framework ef-migrations

我在SQL中有5个表,并使用Entity Framework创建。 但它不再创建表了。

我的背景:

 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; }
}

当我在PMC中使用Update-Database命令时,它不会返回错误。它返回“Running Seed Method”

但它不会在SQL Server中创建表。

我试过了:

Enable-Migrations

Add-Migration Initial
Add-Migration InitialCreate
Add-Migration Initial -IgnoreChanges

Update-Database
Update-Database -Verbose

我创建了所有表格,但无法为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()
        {
        }
    }

Configuration.cs:

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.
            }
        }

0 个答案:

没有答案