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
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With