Migrations not running and throwing error for __EFMigrationsHistory

0

I have Dot net Core 2.2.1 and Entity Framework Core 2.1.3 and Npgsql.EntityFrameworkCore.PostgreSQL 2.0.0 I can not upgrade any of these as this is related to AWS Lambda function which support dot net core 2.2.1 Now when i run Add-Migration InitialCreate it creates the migration and when i type Update-Database it thows an error which is given below

    fail: Microsoft.EntityFrameworkCore.Database.Command[20102]
      Failed executing DbCommand (132ms) [Parameters=[], CommandType='Text', 
    CommandTimeout='30']
      INSERT INTO "__EFMigrationsHistory" ("MigrationId", "ProductVersion")
      VALUES (20190625105712_initialCreate, 2.1.8-servicing-32085);
Npgsql.PostgresException (0x80004005): 42601: syntax error at or near "_initialCreate"
   at Npgsql.NpgsqlConnector.DoReadMessage(Boolean async, DataRowLoadingMode dataRowLoadingMode, Boolean readingNotifications, Boolean isPrependedMessage)
   at Npgsql.NpgsqlConnector.ReadMessage(Boolean async, DataRowLoadingMode dataRowLoadingMode, Boolean readingNotifications)
   at Npgsql.NpgsqlConnector.ReadMessage(Boolean async, DataRowLoadingMode dataRowLoadingMode, Boolean readingNotifications)
   at Npgsql.NpgsqlConnector.ReadExpecting[T](Boolean async)
   at Npgsql.NpgsqlDataReader.NextResult(Boolean async)
   at Npgsql.NpgsqlDataReader.NextResult()
   at Npgsql.NpgsqlCommand.Execute(CommandBehavior behavior, Boolean async, CancellationToken cancellationToken)
   at Npgsql.NpgsqlCommand.ExecuteNonQuery(Boolean async, CancellationToken cancellationToken)
   at Npgsql.NpgsqlCommand.ExecuteNonQuery()
   at Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand.Execute(IRelationalConnection connection, DbCommandMethod executeMethod, IReadOnlyDictionary`2 parameterValues)
Failed executing DbCommand (132ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
INSERT INTO "__EFMigrationsHistory" ("MigrationId", "ProductVersion")
VALUES (20190625105712_initialCreate, 2.1.8-servicing-32085);
Npgsql.PostgresException (0x80004005): 42601: syntax error at or near "_initialCreate"
   at Npgsql.NpgsqlConnector.DoReadMessage(Boolean async, DataRowLoadingMode dataRowLoadingMode, Boolean readingNotifications, Boolean isPrependedMessage)
   at Npgsql.NpgsqlConnector.ReadMessage(Boolean async, DataRowLoadingMode dataRowLoadingMode, Boolean readingNotifications)
   at Npgsql.NpgsqlConnector.ReadMessage(Boolean async, DataRowLoadingMode dataRowLoadingMode, Boolean readingNotifications)
   at Npgsql.NpgsqlConnector.ReadExpecting[T](Boolean async)
   at Npgsql.NpgsqlDataReader.NextResult(Boolean async)
   at Npgsql.NpgsqlDataReader.NextResult()

My dbcontext class is as

public class TraceUIContext : DbContext
    {
        public TraceUIContext(DbContextOptions<TraceUIContext> options):base(options)
        {

        }
        public DbSet<Alarms> Alarms { get; set; }
    }

I tried to create a script file and changed the file to INSERT INTO "__EFMigrationsHistory" ("MigrationId", "ProductVersion") VALUES ('20190625105712_initialCreate', '2.1.8-servicing-32085'); and it executes successfully. I think when running migration it is generating the Values as string but not adding single quote due to which whole migration is failing.

The code generated by migration is as

public partial class initialCreate : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "Alarms",
                columns: table => new
                {
                    Id = table.Column<long>(nullable: false)
                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.SerialColumn),
                    GroupNo = table.Column<long>(nullable: false),
                    GroupN = table.Column<string>(maxLength: 20, nullable: true),
                    ChannelNo = table.Column<long>(nullable: false),
                    ChannelN = table.Column<string>(maxLength: 10, nullable: true),
                    ComputerName = table.Column<string>(maxLength: 40, nullable: true),
                    AlarmType = table.Column<string>(maxLength: 20, nullable: true),
                    AlarmSetPoint = table.Column<string>(maxLength: 10, nullable: true),
                    AlarmStart = table.Column<DateTime>(nullable: false),
                    AlarmAcknowleged = table.Column<DateTime>(nullable: false),
                    AlarmAcknowledgedBy = table.Column<string>(maxLength: 10, nullable: true),
                    AlarmEnd = table.Column<DateTime>(nullable: false),
                    AlarmReason = table.Column<string>(maxLength: 40, nullable: true),
                    AlarmAction = table.Column<string>(maxLength: 40, nullable: true),
                    AlarmValue = table.Column<string>(maxLength: 10, nullable: true),
                    AlarmDelay = table.Column<string>(maxLength: 7, nullable: true),
                    AlarmStatus = table.Column<string>(maxLength: 16, nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Alarms", x => x.Id);
                });
        }

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

It should run the migrations and should be able to create Script that run without issues.

c#
postgresql
.net-core
ef-core-2.1
asked on Stack Overflow Jun 25, 2019 by Naveed Yousaf • edited Jun 25, 2019 by Naveed Yousaf

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0