Hi,
We created our first application on Blazor Server, and published it for IIS, however when opening it for the first time, we found that the database was not created.
Is it necessary to always run DB Migrator? Is there no possibility of creating and updating the Database on the Blazor Server itself?
Thank's
5 Answer(s)
-
0
You can call migration after the application starts. In your blazor-server module you can override
OnPostApplicationInitializationAsync
method:public override async Task OnPostApplicationInitializationAsync(ApplicationInitializationContext context) { await context.ServiceProvider .GetRequiredService<BookStoreDbMigrationService>() // Your applicationDbMigrationService .MigrateAsync(); }
-
0
Hi,
Thank's for the response.
By doing this, the database is successfully created, however the following error is always displayed, and the server does not start. If we remove the OnPostApplicationInitializationAsync after database creation, it runs normally. In DBMigrator this error does not happen.
An exception occurred in the database while saving changes for context type 'Volo.Abp.LanguageManagement.EntityFrameworkCore.LanguageManagementDbContext'. Microsoft.EntityFrameworkCore.DbUpdateException: An error occurred while saving the entity changes. See the inner exception for details. ---> Microsoft.Data.SqlClient.SqlException (0x80131904): Cannot insert duplicate key row in object 'dbo.AbpLanguages' with unique index 'IX_AbpLanguages_CultureName'. The duplicate key value is (tr).
-
0
-
0
-
0
Is it necessary to always run DB Migrator?
You need to use
Migrator
to create a new database.https://docs.abp.io/en/abp/latest/Entity-Framework-Core-Migrations
By doing this, the database is successfully created,
Please undo this.