Миграции не работают и выдают ошибку для __EFMigrationsHistory - PullRequest
0 голосов
/ 25 июня 2019

У меня есть Dot net Core 2.2.1 и Entity Framework Core 2.1.3 и Npgsql.EntityFrameworkCore.PostgreSQL 2.0.0. Я не могу обновить ни один из них, поскольку это связано с функцией AWS Lambda, которая поддерживает ядро ​​dot net 2.2.1Теперь, когда я запускаю Add-Migration InitialCreate, он создает миграцию, и когда я набираю Update-Database, он выдает ошибку, которая приведена ниже

    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()

Мой класс dbcontext имеет вид

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

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

Я попытался создать файл сценария и изменил файл на INSERT INTO "__EFMigrationsHistory" ("MigrationId", "ProductVersion") VALUES ('20190625105712_initialCreate', '2.1.8-servicing-32085');и он успешно выполняется.Я думаю, что при запуске миграции он генерирует значения в виде строки, но не добавляет одинарную кавычку, из-за которой вся миграция завершается неудачей.

Код, сгенерированный миграцией, имеет вид

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");
        }
    }

Он должен работатьмиграции и должны быть в состоянии создать сценарий, который работает без проблем.

...