[英]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(SqlException1 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. 我不明白为什么会这样。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.