【发布时间】:2021-07-12 07:17:06
【问题描述】:
我想构建一个 Web 应用程序,其中包含一个可以为教授分配课程的页面——我已经使用 Identity API 创建了登录-注销/注册页面——为了做到这一点,我正在使用 Razor Pages 实体框架(克鲁德)。我之前已经进行了一些迁移,我想添加另一个名为“InitialCreate”的迁移。我在数据包管理器控制台中输入了以下命令:
Add-Migration InitialCreate -Context ApplicationDbContext
Update-Database -Context ApplicationDbContext
一切都已成功构建,但是当我运行代码并尝试通过我的本地主机 (localhost:x/AlocareMaterii) 访问使用迁移的页面“AlocareMaterii”时,我收到以下错误:
A database operation failed while processing the request.
SqlException: Cannot open database "razor_licenta_runtimeContext-a7b890ea-d1ed-4faa-afdf-88dcf8d382d4Trusted_Connection=True" requested by the login. The login failed. Login failed for user 'DESKTOP-3AH99PG\ninex'.
Use migrations to create the database for razor_licenta_runtimeContext
In Visual Studio, use the Package Manager Console to scaffold a new migration and apply it to the database:
PM> Add-Migration [migration name]
PM> Update-Database
Alternatively, you can scaffold a new migration and apply it from a command prompt at your project directory:
> dotnet ef migrations add [migration name]
> dotnet ef database update
这是我的“appsettings.json”文件:
{
"ConnectionStrings": {
"DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=aspnet-razor_licenta_runtime-53bc9b9d-9d6a-45d4-8429-2a2761773502;Trusted_Connection=True;MultipleActiveResultSets=true",
"razor_licenta_runtimeContext": "Server=(localdb)\\mssqllocaldb;Database=razor_licenta_runtimeContext-a7b890ea-d1ed-4faa-afdf-88dcf8d382d4Trusted_Connection=True;MultipleActiveResultSets=true"
},
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*"
}
【问题讨论】:
标签: database visual-studio asp.net-core asp.net-web-api localdb