简体   繁体   English

从Asp.Net Core 2.1 Web应用程序进行SQL迁移导致Db更新中的NOT关键字错误

[英]NOT keyword error in Db update from SQL migration from Asp.Net Core 2.1 web app

I am migrating a code first domain (Initial creation) in an Asp.Net Core 2.1 web application. 我正在Asp.Net Core 2.1 Web应用程序中迁移代码优先域(初始创建)。

The add-migration command created the following code (non erroring parts removed for brevity) add-migration命令创建了以下代码(为简洁起见,删除了没有错误的部分)

migrationBuilder.CreateIndex(
        name: "RoleNameIndex",
        schema: "BatlCtx",
        table: "AspNetRoles",
        column: "NormalizedName",
        unique: true,
        filter: "[NormalizedName] IS **NOT** NULL");

migrationBuilder.CreateIndex(
        name: "UserNameIndex",
        schema: "BatlCtx",
        table: "AspNetUsers",
        column: "NormalizedUserName",
        unique: true,
        filter: "[NormalizedUserName] IS **NOT** NULL");

Here is the code from the migration for the table creation 这是迁移表创建中的代码

migrationBuilder.CreateTable(
        name: "AspNetUsers",
        schema: "BatlCtx",
        columns: table => new
        {
            Id = table.Column<string>(nullable: false),
            UserName = table.Column<string>(maxLength: 256, nullable: true),
            NormalizedUserName = table.Column<string>(maxLength: 256, nullable: true),
            Email = table.Column<string>(maxLength: 256, nullable: true),
            NormalizedEmail = table.Column<string>(maxLength: 256, nullable: true),
            EmailConfirmed = table.Column<bool>(nullable: false),
            PasswordHash = table.Column<string>(nullable: true),
            SecurityStamp = table.Column<string>(nullable: true),
            ConcurrencyStamp = table.Column<string>(nullable: true),
            PhoneNumber = table.Column<string>(nullable: true),
            PhoneNumberConfirmed = table.Column<bool>(nullable: false),
            TwoFactorEnabled = table.Column<bool>(nullable: false),
            LockoutEnd = table.Column<DateTimeOffset>(nullable: true),
            LockoutEnabled = table.Column<bool>(nullable: false),
            AccessFailedCount = table.Column<int>(nullable: false),
            FirstName = table.Column<string>(maxLength: 50, nullable: false),
            LastName = table.Column<string>(maxLength: 80, nullable: false),
            Gender = table.Column<int>(nullable: false),
            MobilePhone = table.Column<string>(maxLength: 24, nullable: false),
            DateOfBirth = table.Column<DateTime>(nullable: false),
            UserPicture = table.Column<byte[]>(nullable: true),
            TimesLoggedIn = table.Column<int>(nullable: false)
            },
        constraints: table =>
        {
            table.PrimaryKey("PK_AspNetUsers", x => x.Id);
        });

When attempting to update-database for the first time, this error is occurring 首次尝试更新数据库时,发生此错误

System.Data.SqlClient.SqlException (0x80131904): Incorrect syntax near the keyword 'NOT'. System.Data.SqlClient.SqlException(0x80131904):关键字“ NOT”附近的语法不正确。 at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action 1 wrapCloseInAction) at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action 1 wrapCloseInAction) at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) Note: I removed the "filter: "[NormalizedName] IS NOT NULL"" part of the code, but I am still getting the same error 在System.Data.SqlClient.SqlInternalConnection.OnError(SqlException 1 wrapCloseInAction) at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action 1 wrapCloseInAction)在System.Data.SqlClient.SqlInsert.SqlServer.TdsParser .ThrowExceptionAndWarning(TdsParserStateObject stateObj,Boolean callerHasConnectionLock,布尔asyncClose) 注意:我删除了代码的“过滤器:“ [NormalizedName] IS NOT NULL”“部分,但仍然遇到相同的错误

The bolded NOT keywords in the CreateIndex methods (first code snippet in post) are the culprit. 罪魁祸首是CreateIndex方法中的粗体NOT关键字(帖子中的第一个代码段)。 Now, I could understand if I WROTE that code, but this is generated code from the add-migration. 现在,我可以理解是否编写了该代码,但这是从add-migration生成的代码。 I don't understand why this is erring. 我不明白为什么会这样。

Please go through this Post 请通过这篇文章

You may remove the filter and run update-database. 您可以删除过滤器并运行update-database。 Like below: 如下所示:

migrationBuilder.CreateIndex(
    name: "RoleNameIndex",
    schema: "BatlCtx",
    table: "AspNetRoles",
    column: "NormalizedName",
    unique: true);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从存储库部署ASP.NET Core Web App + SQL - Deploying ASP.NET Core Web App + SQL from a repository 从移动设备访问托管在本地主机上的 ASP.NET Core 2.1 Web 应用程序 - Access ASP.NET Core 2.1 web app hosted on localhost from mobile device 从2.1-&gt; 2.2的ASP.NET Core迁移-Azure部署中的依赖关系问题 - ASP.NET Core Migration from 2.1 -> 2.2 Issue with dependencies in Azure deployment ASP.NET Core 2.1,C#应用程序,C#Web服务,访问SQL数据库 - asp.net core 2.1, C# app, c# web service, access SQL database 从asp.net迁移到asp.net核心 - Migration from asp.net to asp.net core 从 React Native 访问 ASP.NET Core 2.1 Web API 时“无法对 HTTPS 连接进行身份验证” - 'Failed to authenticate HTTPS connection' while accessing ASP.NET Core 2.1 Web API from React Native 如何使用提取将JavaScript中的FormData发送到ASP.NET Core 2.1 Web API - How to send FormData from javascript to ASP.NET Core 2.1 web API using fetch 从控制台应用程序启动 ASP.NET Core Web API - Start ASP.NET Core Web API from a Console App ASP.NET Core 2.1从类库引用ApplicationDbContext - ASP.NET Core 2.1 Referring to ApplicationDbContext from Class Library 从 ASP.NET Core 2.1 中的 MySqlConnector 获取查询日志 - Get query logs from MySqlConnector in ASP.NET Core 2.1
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM