c# - 无法从脚手架创建新帐户
问题描述
我正在尝试使用新的 .Net Core 2.1 中的新身份脚手架从头开始创建授权和身份验证,但不断收到此错误。
SqlException:对象名称“AspNetUsers”无效。
RegisterModel 无法在此行执行:
var result = await _userManager.CreateAsync(user, Input.Password);
IDENTITYHOSTINGSTARTUP.CS
[assembly: HostingStartup(typeof(Authorize.Areas.Identity.IdentityHostingStartup))]
namespace Authorize.Areas.Identity
{
public class IdentityHostingStartup : IHostingStartup
{
public void Configure(IWebHostBuilder builder)
{
builder.ConfigureServices((context, services) => {
services.AddDbContext<AuthorizeContext>(options =>
options.UseSqlServer(
context.Configuration.GetConnectionString("AuthorizeContextConnection")));
services.AddDefaultIdentity<AuthorizeUser>()
.AddEntityFrameworkStores<AuthorizeContext>()
.AddDefaultTokenProviders();
});
}
}
}
解决方案
此错误通常表明您的数据库中没有 AspNetUsers 表。您是否运行了脚手架中提供的迁移?这可以通过 powershell 或控制台终端来完成。导航到 Web 项目并Update-Database
在使用 powershell 或dotnet ef database update
控制台时执行。
https://docs.microsoft.com/en-us/ef/core/managing-schemas/migrations/
推荐阅读
- rust - 如何在编译期间检查 Rust 中设置的功能?
- azure - ARM 模板中的 AlertRule 条件中的 $type
- android - 嵌入在 Android 应用程序中的 Unity (Vuforia)
- regex - 用于删除小数的正则表达式
- c - 局部变量赋值是否构成副作用?
- firebase - Firebase serve 命令不会运行整个脚本代码(这反过来应该在 firebase serve 命令上的聚合物 Web 应用程序中的 Web 应用程序中显示页面
- ssis - 将公共 Google 电子表格中的数据导入 SSIS?
- javascript - 如果每个值有多个,如何根据其值从数组中仅删除一个元素
- c# - WPF:有没有办法在使用 Oblique FontStyle 时避免 TextBox 文本剪辑?
- docker - 轻微的 Docker 构建问题