Add-Migration works but I can't update-database with EF Core

0

When adding the migration, everything goes well (Entity Framework Core 2.2.6-servicing-10079 initialized 'ConsultarDbContext' using provider 'Microsoft.EntityFrameworkCore.SqlServer' with options: None), but when updating-database errors occur that I see no reason to happen

I tried to change in the migration itself created some fields, but continued with the same problem.

This is the migration created, it seems to me all ok

public partial class initial : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "PRODUTO",
                columns: table => new
                {
                    COD_PRODUTO = table.Column<string>(type: "varchar(100)", nullable: false),
                    DES_PRODUTO = table.Column<string>(type: "char(1)", nullable: true),
                    STA_STATUS = table.Column<string>(type: "char(1)", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_PRODUTO", x => x.COD_PRODUTO);
                });

            migrationBuilder.CreateTable(
                name: "PRODUTO_COSIF",
                columns: table => new
                {
                    COD_PRODUTO = table.Column<string>(type: "varchar(100)", nullable: false),
                    COD_COSIF = table.Column<string>(type: "varchar(100)", nullable: false),
                    COD_CLASSIFICACAO = table.Column<string>(type: "char(6)", nullable: true),
                    STA_STATUS = table.Column<string>(type: "varchar(100)", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_PRODUTO_COSIF", x => new { x.COD_PRODUTO, x.COD_COSIF });
                    table.ForeignKey(
                        name: "FK_PRODUTO_COSIF_PRODUTO_COD_PRODUTO",
                        column: x => x.COD_PRODUTO,
                        principalTable: "PRODUTO",
                        principalColumn: "COD_PRODUTO",
                        onDelete: ReferentialAction.Restrict);
                });

            migrationBuilder.CreateTable(
                name: "MOVIMENTO_MANUAL",
                columns: table => new
                {
                    DAT_MES = table.Column<int>(nullable: false),
                    DAT_ANO = table.Column<int>(nullable: false),
                    NUM_LANCAMENTO = table.Column<int>(nullable: false),
                    COD_PRODUTO = table.Column<int>(nullable: false),
                    COD_COSIF = table.Column<int>(nullable: false),
                    DES_DESCRICAO = table.Column<string>(type: "varchar(100)", maxLength: 50, nullable: true),
                    DAT_MOVIMENTO = table.Column<DateTime>(type: "smalldatetime", nullable: false),
                    COD_USUARIO = table.Column<string>(type: "varchar(100)", maxLength: 15, nullable: true),
                    VAL_VALOR = table.Column<double>(type: "double(18,2)", nullable: false),
                    ProdutoCosifCOD_PRODUTO = table.Column<string>(nullable: true),
                    ProdutoCosifCOD_COSIF = table.Column<string>(nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MOVIMENTO_MANUAL", x => new { x.DAT_ANO, x.DAT_MES, x.NUM_LANCAMENTO, x.COD_PRODUTO, x.COD_COSIF });
                    table.ForeignKey(
                        name: "FK_MOVIMENTO_MANUAL_PRODUTO_COSIF_ProdutoCosifCOD_PRODUTO_ProdutoCosifCOD_COSIF",
                        columns: x => new { x.ProdutoCosifCOD_PRODUTO, x.ProdutoCosifCOD_COSIF },
                        principalTable: "PRODUTO_COSIF",
                        principalColumns: new[] { "COD_PRODUTO", "COD_COSIF" },
                        onDelete: ReferentialAction.Restrict);
                });

            migrationBuilder.CreateIndex(
                name: "IX_MOVIMENTO_MANUAL_ProdutoCosifCOD_PRODUTO_ProdutoCosifCOD_COSIF",
                table: "MOVIMENTO_MANUAL",
                columns: new[] { "ProdutoCosifCOD_PRODUTO", "ProdutoCosifCOD_COSIF" });
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "MOVIMENTO_MANUAL");

            migrationBuilder.DropTable(
                name: "PRODUTO_COSIF");

            migrationBuilder.DropTable(
                name: "PRODUTO");
        }
    }

This is the error message on PMC:

ailed executing DbCommand (1ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
CREATE TABLE [MovimentosManuais] (
    [DAT_MES] int NOT NULL,
    [DAT_ANO] int NOT NULL,
    [NUM_LANCAMENTO] int NOT NULL,
    [COD_PRODUTO] int NOT NULL,
    [COD_COSIF] int NOT NULL,
    [DES_DESCRICAO] varchar(100) NULL,
    [DAT_MOVIMENTO] smalldatetime NOT NULL,
    [COD_USUARIO] varchar(100) NULL,
    [VAL_VALOR] double(18,2) NOT NULL,
    [ProdutoCosifCOD_PRODUTO] varchar(100) NULL,
    [ProdutoCosifCOD_COSIF] varchar(100) NULL,
    CONSTRAINT [PK_MovimentosManuais] PRIMARY KEY ([DAT_ANO], [DAT_MES], [NUM_LANCAMENTO], [COD_PRODUTO], [COD_COSIF]),
    CONSTRAINT [FK_MovimentosManuais_PRODUTO_COSIF_ProdutoCosifCOD_PRODUTO_ProdutoCosifCOD_COSIF] FOREIGN KEY ([ProdutoCosifCOD_PRODUTO], [ProdutoCosifCOD_COSIF]) REFERENCES [PRODUTO_COSIF] ([COD_PRODUTO], [COD_COSIF]) ON DELETE NO ACTION
);
System.Data.SqlClient.SqlException (0x80131904): Incorrect syntax near '('.
Incorrect syntax near 'ACTION'.
   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)
   at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   at System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean async, Int32 timeout, Boolean asyncWrite)
   at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource`1 completion, Boolean sendToPipe, Int32 timeout, Boolean asyncWrite, String methodName)
   at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
   at Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand.Execute(IRelationalConnection connection, DbCommandMethod executeMethod, IReadOnlyDictionary`2 parameterValues)
   at Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand.ExecuteNonQuery(IRelationalConnection connection, IReadOnlyDictionary`2 parameterValues)
   at Microsoft.EntityFrameworkCore.Migrations.MigrationCommand.ExecuteNonQuery(IRelationalConnection connection, IReadOnlyDictionary`2 parameterValues)
   at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationCommandExecutor.ExecuteNonQuery(IEnumerable`1 migrationCommands, IRelationalConnection connection)
   at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.Migrate(String targetMigration)
   at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.UpdateDatabase(String targetMigration, String contextType)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.UpdateDatabase.<>c__DisplayClass0_1.<.ctor>b__0()
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
ClientConnectionId:ca99d5b6-4f58-4bc8-950e-98c3962bf3ea
Error Number:102,State:1,Class:15
Incorrect syntax near '('.
Incorrect syntax near 'ACTION'.
c#
.net-core
entity-framework-core
asked on Stack Overflow Oct 20, 2019 by Thiago Cruz

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0