简体   繁体   English

C#EF添加迁移-强制不起作用

[英]C# EF Add-migration -Force doesn't work

I'm trying to overwrite the InitialModel Migration because i added a new DbSet under customer DbSet like this : 我试图覆盖InitialModel迁移,因为我在客户DbSet下添加了一个新的DbSet,如下所示:

    public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
    {
        public DbSet<Customer> Customers { get; set; }
        public DbSet<Movie> Movies { get; set; }


        public ApplicationDbContext()
            : base("DefaultConnection", throwIfV1Schema: false)
        {
        }

        public static ApplicationDbContext Create()
        {
            return new ApplicationDbContext();
        }
    }
}

After I added the Movies DbSet i run 添加电影DbSet后,我运行

add-migration InitialModel -Force 

To overwrite the IntialModel migration file and create the Movies Table, so that it will appear as createTable in the up method inside InitialModel migration file like what happend with customers table like this : 要覆盖IntialModel迁移文件并创建Movies Table,以使其在createModel迁移文件内的up方法中以createTable的形式出现,就像客户表发生的情况一样,如下所示:

 public partial class IitialModel : DbMigration
    {
        public override void Up()
        {

            CreateTable(
                "dbo.Customers",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Name = c.String(),
                    })
                .PrimaryKey(t => t.Id);

Every time i tried to run 每次我尝试跑步

add-migration InitialModel -Force

after adding the DbSet it creates a new migration file called InitialModel1 it's not what i want, i want to overwrite the InitialModel migration fie to createTable called Movies inside it? 添加DbSet之后,它会创建一个名为InitialModel1的新迁移文件,这不是我想要的,我想将InitialModel迁移文件覆盖到其中的称为Movies的createTable吗?

please try specifying the name explicitly and add the verbose flag: 请尝试明确指定名称并添加详细标志:

Add-Migration -Name InitialModel -Verbose -Force

Then please show us the detailed log. 然后,请向我们显示详细的日志。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM