[英]How to add another tables to project with identity (EF, Code First)
I have a Model "Phone" 我有一个型号“手机”
public class Phone
{
[Key]
public Guid Id { get; set; }
public string NameModel { get; set; }
[MaxLength(100)]
public int SerialNumber { get; set; }
}
End add this model to DBContext with Identity: 最后将此模型添加到具有标识的DBContext中:
public class AppDbContext : IdentityDbContext<AppUser>
{
public AppDbContext (DbContextOptions<AppDbContext> options)
: base(options)
{
Database.EnsureCreated();
}
public DbSet<Phone> Phones { get; set; }
}
Next, I perform the database migration: 接下来,我执行数据库迁移:
dotnet ef migrations add InitialMigration
and: 和:
dotnet ef database update
But table "Phones" is not added to my database. 但是表“ Phones”没有添加到我的数据库中。 What am I doing wrong?
我究竟做错了什么?
EnsureCreated and Migrations don't work well together.
确保创建和迁移不能很好地协同工作。 If you're using Migrations, don't use EnsureCreated to initialize the schema.
如果您使用的是迁移,请不要使用GuaranteeCreated初始化架构。
Source: https://docs.microsoft.com/en-us/ef/core/managing-schemas/ensure-created 来源: https : //docs.microsoft.com/en-us/ef/core/managing-schemas/ensure-created
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.