繁体   English   中英

如何添加另一个表到具有标识的项目(EF,代码优先)

[英]How to add another tables to project with identity (EF, Code First)

我有一个型号“手机”

public class Phone
    {
        [Key]
        public Guid Id { get; set; }
        public string NameModel { get; set; }
        [MaxLength(100)]
        public int SerialNumber { get; set; }
    } 

最后将此模型添加到具有标识的DBContext中:

public class AppDbContext : IdentityDbContext<AppUser>
    {
        public AppDbContext (DbContextOptions<AppDbContext> options)
            : base(options)
        {
            Database.EnsureCreated();
        }

        public DbSet<Phone> Phones { get; set; }
    }

接下来,我执行数据库迁移:

dotnet ef migrations add InitialMigration

和:

dotnet ef database update

但是表“ Phones”没有添加到我的数据库中。 我究竟做错了什么?

确保创建和迁移不能很好地协同工作。 如果您使用的是迁移,请不要使用GuaranteeCreated初始化架构。

来源: https : //docs.microsoft.com/en-us/ef/core/managing-schemas/ensure-created

暂无
暂无

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

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