Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running DNX (EF7) database migration on Azure

I've been running a MVC project with ASP.NET 4.6 and EF7 locally and everything works fine. I ran the dnx . ef migration Initial commands to create the database tables, and everything ran fine. The app works.

With Azure I have one problem, I can't seem to run the dnx . ef migration command so my SQL database is empty. I've debugged Startup.cs and the connection string is correctly retrieved, but the tables are not there.

I used the Publish option in Visual Studio 2015 to deploy to my Azure Web App.

How can I run this command on my web app? Is there another way to generate the database?

Thanks

like image 752
Joao Sousa Avatar asked Oct 17 '15 14:10

Joao Sousa


People also ask

How do I migrate a database from Oracle to Azure?

Use Azure Database Migration Service to migrate your relational databases to Azure You can use Azure Database Migration Service to migrate relational databases like SQL Server, Oracle, and MySQL to Azure, whether your target database is Azure SQL Database, Azure SQL Database Managed Instance, or SQL Server on an Azure VM.

Are automatic migrations available in EF Core?

I think automatic migrations are not available in EF Core. But, I tried to do something like this (from what I gathered online): public void Configure ( IApplicationBuilder app, IHostingEnvironment env , IServiceProvider provider ) { // Automatic migrations. if ( env.

Can I migrate from on-premises SQL to Azure SQL database managed instance?

In most cases, though, Azure SQL Database Managed Instance can provide everything you need to migrate from on-premises SQL servers, so migration to a SQL Server VM should be your last resort to try.

When is the DB migration done after the update?

The db migration is done at deploy time, not in the "first run after the update" Sorry, something went wrong. @ilmax I do not have the option to choose migration when I deploy, as I have two projects in my case.


1 Answers

It seems that the EF team has eliminated the infamous database initializers and offers a more versatile method for that on version 7.

Just use these methods in the pipeline before any call to the database,

yourDbContext.Database.EnsureCreated();

to create the database in case it doesn't exists and

yourDbContext.Database.Migrate();

to apply migrations (if you use this feature later). Both methods above also have an asynchronous version.

In my solution I have created an static class that I use to initialize the database and seed it with some data. I call the Seed method from the Configure method in the Startup class when some condition is met.

like image 158
Vi100 Avatar answered Oct 01 '22 17:10

Vi100