Hello,
I'm learning Blazor ( do it as an hobby) and created my first WebApp.
No I want to publish the app on a web-server (Microsoftserver) and running in problems.
I followed all the necessery steps in the right order (thanks to CodingWithJannick on Youtube)
But if the app starts, it failed at the creation of the databes tables, means the database migration doesn't work. The logfile shows the error in the line
_Db.Database.Migrate();
of the code (below).
On my local computer it works. After starting the app create the new database with the tables.
The connection string is ok, DbContext is also ok.
Database user has the rights to create a database.
What could be the mistake which I do?
Thanks for Tipps and help.
Juergen
Program.cs
...
ApplyMigration;
appRun;
void ApplyMigration()
{
using (var scope = app.Services.CreateScope())
{
var _Db = scope.ServiceProvider.GetRequiredService<ApplicationDbContext>();
if(_Db!=null)
{
if(_Db.Database.GetMigrations().Any())
{
_Db.Database.Migrate();
}
}
}
}