dotnet / efcore

EF Core is a modern object-database mapper for .NET. It supports LINQ queries, change tracking, updates, and schema migrations.
https://docs.microsoft.com/ef/
MIT License
13.75k stars 3.18k forks source link

Migration scripts are always generated for "Development" environment #11950

Open macsux opened 6 years ago

macsux commented 6 years ago

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

bricelam commented 6 years ago

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

macsux commented 6 years ago

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

bricelam commented 6 years ago

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

divega commented 6 years ago

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

bricelam commented 6 years ago

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

SET ASPNETCORE_ENVIRONMENT=Production
devenv
divega commented 6 years ago

@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?

bricelam commented 6 years ago

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

divega commented 6 years ago

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

Rick-Anderson commented 4 years ago

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

GeorgeAlexandruD commented 1 year ago

@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.

rick commented 1 year ago

bladdow