Search code examples
sql-serverasp.net-mvcentity-frameworkazureef-code-first

Entity Framework .Database.Initialize(true) doesn't create tables while working on Azure


I have mvc application. I'm using code first approach. When new tenant registers to system i create new database with azure sql fluent api.

Database is created without problem but it's empty as expected. To initialize data from my migration i call myDB.Database.Initialize(true); it passes without any error but tables are not created.

To be sure i run project in my local computer and point connection string to azure database after running myDB.Database.Initialize(true); database is initialized.

I researched on internet people points to timeout issue for applying migration.Even i don't have any timeout issue extended timeout for migration but still same.

It creates table when i run from my computer (connected to azure db) but doesn't create when running on azure even i don't see any error.

Any idea why it's not creating on azure sql database ?

Tried to change timeout for migration configuration.


Solution

  • According to @Cozdemir's comment:

    I solved my problem with following thead. I think my problem was because my applications is multi tenant. i connect to database with connection string dynamicly. Each tenant connects to his/her database via connection string dynamicly. So connection strings was not in my webconfig. That's why i needed to specify connection string. And above thread is exactly about that. I implemented that code and it worked. Reference: EF Code First MigrateDatabaseToLatestVersion accepts connection string Name from config

    I posted this as answer and this can be beneficial to other community members.