Код: Выделить всё
XXDbContext dbContext = scope.ServiceProvider.GetRequiredService();
// passes
var canConnect = await dbContext.Database.CanConnectAsync();
if (!canConnect)
{
throw new ApplicationException("Cannot establish connection to the database");
}
// does nothing
var pendingMigrations = (await dbContext.Database.GetPendingMigrationsAsync()).ToList();
logger.LogInformation($"Applying pending migrations in environment...");
foreach (var mug in pendingMigrations)
{
logger.LogInformation(mug);
}
// fails
if (await TableExistsAsync(dbContext, "Users", "BL") == false)
{
logger.LogWarning("Database tables do not exist. Creating..");
dbContext.Database.EnsureCreated();
logger.LogWarning("Database schema created successfully");
}
if (pendingMigrations.Any())
{
var migrationsList = string.Join(", ", pendingMigrations);
logger.LogWarning($"Database has pending migrations: {migrationsList}");
await dbContext.Database.MigrateAsync();
logger.LogInformation("Migrations applied successfully");
}
< /code>
Я попробовал другие подходы с < /p>
var script = dbContext.Database.GenerateCreateScript();
dbContext.Database.ExecuteSqlRaw(script);
< /code>
Также не удается, на этот раз с ошибкой форматирования SQL: < /p>
FATAL: Database validation failed. The application cannot start.System.FormatException: Index (zero based)
must be greater than or equal to zero and less than the size of the argument list.at System.Text.ValueStringBuilder.AppendFormatHelpe
Подробнее здесь: https://stackoverflow.com/questions/797 ... ble-server
Мобильная версия