如果在使用Asp.net Core的IdentityDbContext时,只创建了身份表,而没有创建其他表,可以尝试以下解决方法:
services.AddDbContext(options =>
options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
services.AddIdentity()
.AddEntityFrameworkStores()
.AddDefaultTokenProviders();
其中,YourDbContext是你自己创建的DbContext类,YourUser和YourRole是你自己定义的用户和角色实体类。
public class YourDbContext : IdentityDbContext
{
public YourDbContext(DbContextOptions options)
: base(options)
{
}
}
其中,YourUser和YourRole是你自己定义的用户和角色实体类,string是用户和角色的主键类型。
Add-Migration InitialCreate
Update-Database
这将创建数据库迁移脚本并将其应用于数据库。
public class YourDbContext : IdentityDbContext
{
public DbSet YourEntities { get; set; }
public YourDbContext(DbContextOptions options)
: base(options)
{
}
protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder);
// Configure your entity mappings here
builder.Entity().ToTable("YourEntities");
}
}
其中,YourEntity是你要创建的其他实体类。
通过以上步骤,应该能够正确地创建你所需的其他表。如果问题仍然存在,可以检查日志文件或调试程序以查找更多详细信息。