【发布时间】:2021-08-21 13:24:58
【问题描述】:
我构建了一个 asp.net core 5.0 应用程序并在本地使用SQLlite。当我尝试使用 Visual Studio 2019 社区发布到 Aruze Web 应用程序时,出现错误。
执行命令:dotnet ef migrations script --no-build --idempotent --configuration Release --output "ApplicationDbContext.sql" --context ApplicationDbContext
System.NotSupportedException:生成幂等脚本 SQLite 目前不支持迁移。了解更多信息, 见http://go.microsoft.com/fwlink/?LinkId=723262。
我的 startup.cs 如下所示:
services.AddDbContext<ApplicationDbContext>(options =>
{
if (Environment.IsProduction())
{
options.UseSqlServer(Configuration.GetConnectionString("ApplicationDbContex"));
}
else
{
options.UseSqlite("Data Source = Application.db");
}
});
似乎在发布运行时使用的是 SQLlite 设置,而不是 azure sql 数据库的设置。
如何配置 Visual Studio 2019 Publishing 以创建 Azure SQl 数据库的迁移?
更新 1:
Publish 为 Configuration 提供了两种设置:Debug 或 Release
通过将发布配置设置为发布(这是默认设置)并使用 If DEBUG
,我能够让发布功能使用正确的数据库 options.UseSqlServer(Configuration.GetConnectionString("ApplicationConnection"));
#if DEBUG
options.UseSqlite("Data Source = Application.db");
#endif
更新 2:
正如@poke 指出的迁移是特定于平台的,SQLlite 的迁移文件并不总是适用于 MS SQL。使用 SQLlite 生成的迁移文件并发布到 Azure Web 应用程序并使用 azure sql 数据库时,出现此错误:表 'IdentityUser' 中的列 'Id' is of an type that is invalid for use as key column在索引中。
查看迁移文件中的代码,Id 列设置为 Text!我认为 SQL 对此并不满意。
IF NOT EXISTS(SELECT * FROM [__EFMigrationsHistory] WHERE [MigrationId] = N'20210601213159_InitialCreate')
BEGIN
CREATE TABLE [IdentityUser] (
[Id] TEXT NOT NULL,
[UserName] TEXT NULL,
【问题讨论】:
标签: visual-studio entity-framework asp.net-core azure-web-app-service