File tree Expand file tree Collapse file tree 1 file changed +25
-12
lines changed
Expand file tree Collapse file tree 1 file changed +25
-12
lines changed Original file line number Diff line number Diff line change @@ -54,23 +54,36 @@ public static void MigrateDb(IWebHost webHost)
5454 {
5555 using ( var scope = webHost . Services . GetService < IServiceScopeFactory > ( ) . CreateScope ( ) )
5656 {
57- using ( var dbContext = scope . ServiceProvider . GetRequiredService < BaseDbContext > ( ) )
57+
58+ BaseDbContext dbContext = null ;
59+ try
60+ {
61+ dbContext = scope . ServiceProvider . GetRequiredService < BaseDbContext > ( ) ;
62+ }
63+ catch { }
64+
65+ if ( dbContext != null )
5866 {
59- try
67+ using ( dbContext = scope . ServiceProvider . GetRequiredService < BaseDbContext > ( ) )
6068 {
61- var connectionStrings =
62- scope . ServiceProvider . GetRequiredService < IWritableOptions < ConnectionStrings > > ( ) ;
63- if ( connectionStrings . Value . DefaultConnection != "..." )
69+ try
6470 {
65- dbContext . Database . Migrate ( ) ;
71+ var connectionStrings =
72+ scope . ServiceProvider . GetRequiredService < IWritableOptions < ConnectionStrings > > ( ) ;
73+ if ( connectionStrings . Value . DefaultConnection != "..." )
74+ {
75+ dbContext . Database . Migrate ( ) ;
76+ }
6677 }
67- }
68- catch ( Exception e )
69- {
70- var logger = scope . ServiceProvider . GetRequiredService < ILogger < Program > > ( ) ;
71- logger . LogError ( e , "Error while migrating db" ) ;
72- }
78+ catch ( Exception e )
79+ {
80+ var logger = scope . ServiceProvider . GetRequiredService < ILogger < Program > > ( ) ;
81+ logger . LogError ( e , "Error while migrating db" ) ;
82+ }
83+ }
7384 }
85+
86+
7487 }
7588 }
7689
You can’t perform that action at this time.
0 commit comments