efcore icon indicating copy to clipboard operation
efcore copied to clipboard

Migration scripts are always generated for "Development" environment

Open macsux opened this issue 6 years ago • 9 comments

dotnet ef migrations script always defines Development environmental variable. For applications that use InMemory EF provider when running in Development mode by defining multiple Configure{EnvironmentName}Services blocks this creates a problem, especially when trying to publish to Azure.

Exception message:
Microsoft.EntityFrameworkCore.InMemory is not a Relational provider and therefore cannot be use with Migrations.

Steps to reproduce

Problem is visible in https://github.com/dotnet-architecture/eShopOnWeb when trying to publish on azure and apply migrations on publish.

Further technical details

EF Core version: 2.0.2 Database Provider: Mixed Operating system: IDE: Visual Studio 2017 15.6.2

macsux avatar May 09 '18 18:05 macsux

You can manually set the ASPNETCORE_ENVIRONMENT environment variable before calling dotnet ef.

bricelam avatar May 09 '18 18:05 bricelam

I don't call dotnet ef directly - it's being called for me by Visual Studio during a publish to azure.

macsux avatar May 09 '18 21:05 macsux

Interesting. We may need to add an option to the publish dialog for this...

bricelam avatar May 09 '18 22:05 bricelam

@bricelam to provide workaround. @divega to follow up about how this works on deployment.

divega avatar May 10 '18 17:05 divega

To work around this, you can set the environment variable before launching Visual Studio when publishing:

SET ASPNETCORE_ENVIRONMENT=Production
devenv

bricelam avatar May 11 '18 16:05 bricelam

@bricelam, should we treat this as a duplicate of https://github.com/aspnet/EntityFrameworkCore/issues/8695? Otherwise can you remind me what this one is about?

divega avatar Jul 25 '18 00:07 divega

We were going to follow up with the Web Publish team about adding an option in the UI to specify the environment.

bricelam avatar Jul 26 '18 20:07 bricelam

@mlorbetske is now tracking this in his list. Clearing up fields to decide what to do with this issue.

divega avatar Oct 07 '18 12:10 divega

To work around this, you can set the environment variable before launching Visual Studio when publishing:

SET ASPNETCORE_ENVIRONMENT=Production
devenv

Or on the Properties > Debug debug tab set it

image

Rick-Anderson avatar Sep 17 '20 01:09 Rick-Anderson

@rick

To work around this, you can set the environment variable before launching Visual Studio when publishing:

SET ASPNETCORE_ENVIRONMENT=Production
devenv

Or on the Properties > Debug debug tab set it

image

And? how do I change between environments? You can't just say "this is solution" but then not show how it works.

If I manually change the variable (ew!) then it stays changed no matter what mode I run visual studio in. Please be specific, and clear, in your answers. Also when writing @microsoft docs. We ain't all geniuses with 30 years experience.

GeorgeAlexandruD avatar Sep 20 '23 11:09 GeorgeAlexandruD

bladdow

rick avatar Oct 13 '23 14:10 rick