如何将另一个表添加到具有标识的项目(EF,代码优先)
How to add another tables to project with identity (EF, Code First)
我有模特"Phone"
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
但是 table "Phones" 没有添加到我的数据库中。我做错了什么?
EnsureCreated and Migrations don't work well together. If you're using
Migrations, don't use EnsureCreated to initialize the schema.
来源:https://docs.microsoft.com/en-us/ef/core/managing-schemas/ensure-created
我有模特"Phone"
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
但是 table "Phones" 没有添加到我的数据库中。我做错了什么?
EnsureCreated and Migrations don't work well together. If you're using Migrations, don't use EnsureCreated to initialize the schema.
来源:https://docs.microsoft.com/en-us/ef/core/managing-schemas/ensure-created