执行 DbCommand 失败(2ms)[Parameters=[], CommandType='Text',,关键字“NOT”附近的语法不正确

问题描述 投票:0回答:1

我在下面的屏幕截图中收到错误。添加迁移初始代码成功。 然后,当我说更新数据库时,我在屏幕上看到错误。 我的迁移代码如下。您能帮助我吗?我的产品类别可能有问题吗?

[在此处输入图像描述][1]

            migrationBuilder.CreateTable(
                name: "Categories",
                columns: table => new
                {
                    Id = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    Name = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: false),
                    CreatedDate = table.Column<DateTime>(type: "datetime2", nullable: false),
                    UpdatedDate = table.Column<DateTime>(type: "datetime2", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Categories", x => x.Id);
                });][1]

        migrationBuilder.CreateTable(
            name: "Product",
            columns: table => new
            {
                Id = table.Column<int>(type: "int", nullable: false)
                    .Annotation("SqlServer:Identity", "1, 1"),
                Name = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: false),
                Stock = table.Column<int>(type: "int", nullable: false),
                Price = table.Column<decimal>(type: "decimal(18,2", nullable: false),
                CategoryID = table.Column<int>(type: "int", nullable: false),
                CreatedDate = table.Column<DateTime>(type: "datetime2", nullable: false),
                UpdatedDate = table.Column<DateTime>(type: "datetime2", nullable: true)
            },
            constraints: table =>
            {
                table.PrimaryKey("PK_Product", x => x.Id);
                table.ForeignKey(
                    name: "FK_Product_Categories_CategoryID",
                    column: x => x.CategoryID,
                    principalTable: "Categories",
                    principalColumn: "Id",
                    onDelete: ReferentialAction.Cascade);
            });

        migrationBuilder.CreateTable(
            name: "ProductFeautre",
            columns: table => new
            {
                Id = table.Column<int>(type: "int", nullable: false)
                    .Annotation("SqlServer:Identity", "1, 1"),
                Color = table.Column<string>(type: "nvarchar(max)", nullable: false),
                Height = table.Column<int>(type: "int", nullable: false),
                Width = table.Column<int>(type: "int", nullable: false),
                ProductID = table.Column<int>(type: "int", nullable: false)
            },
           
c# entity-framework asp.net-core .net-core entity-framework-core
1个回答
0
投票

在您的产品表中,价格字段decimal(18,2的语句缺少右括号,应为decimal(18,2):

Price = table.Column<decimal>(type: "decimal(18,2)", nullable: false),

如果错误仍然存在,您可以提供更详细的错误信息。

© www.soinside.com 2019 - 2024. All rights reserved.