I have a test and live db. To test the db-migration I use the syntax Add-Migration ...and Update-Databasein the Package Manager Console. But for live db, I want to do this programmatically when the application is running.
The following code did not help me:
context.Database.Migrate();
I have an error Invalid object name 'TempTenants'when I try to add a record to a table that does not exist. This is my new table.
But I have a table _EFMigrationsHistory. And there are all my migrations, even those that have not been applied. But I do not see the new table.
I will have the same result if I manually delete the table from test db and try to reproduce the error.
So, it context.Database.Migrate();creates only a new db with all migrations, if it does not exist, but does not update (apply migrations) the existing db.
Can I do it? And how can I resolve this?
source
share