microsoft / microsoft/aspire

Issue when creating EF Core Migration

Open
#5,680 4 comments 3 reactions 0 assignees View on GitHub
area-integrations
Dominant language
C#
Stars
6.3k
Forks
991
Avg merge
2d 15h
Merged PRs (30d)
196

Description

### Is there an existing issue for this?

- [X] I have searched the existing issues

### Describe the bug

There are some discussion (e.g., https://github.com/dotnet/aspire/issues/398) about how to run migrations. However, I ran into the issue in creating migrations. It's working as long as I use something like this `builder.AddNpgsqlDbContext(ServiceNames.DATABASE_EMPLS.NAME)`. When I add `builder.AddNpgsqlDataSource(ServiceNames.DATABASE_EMPLS.NAME)` I get the following error with the command
`dotnet ef migrations add update -p ..\AspireApp.Data.Postgres\`

```
Unable to create a 'DbContext' of type ''. The exception 'ConnectionString is missing. It should be provided in 'ConnectionStrings:employee-db' or under the 'ConnectionString' key in 'Aspire:Npgsql' configuration section.' was thrown while attempting to create an instance. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728
```

Full example: https://github.com/fkamp/aspire-ef-migration-issue
Can someone give me a pointer if that's my incompetency or if it's a bug.

Thanks!

### Expected Behavior

After issuing `dotnet ef migrations add update -p ..\AspireApp.Data.Postgres\` migrations are added to the project without any error.

### Steps To Reproduce

Clone and run https://github.com/fkamp/aspire-ef-migration-issue

### Exceptions (if any)

Unable to create a 'DbContext' of type ''. The exception 'ConnectionString is missing. It should be provided in 'ConnectionStrings:employee-db' or under the 'ConnectionString' key in 'Aspire:Npgsql' configuration section.' was thrown while attempting to create an instance. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728

### .NET Version info

.NET SDK:
Version: 8.0.400
Commit: 36fe6dda56
Workload version: 8.0.400-manifests.f51a3a6b
MSBuild version: 17.11.3+0c8610977

Runtime Environment:
OS Name: Windows
OS Version: 10.0.26100
OS Platform: Windows
RID: win-x64
Base Path: C:\Program Files\dotnet\sdk\8.0.400\

.NET workloads installed:
Configured to use loose manifests when installing new manifests.
[aspire]
Installation Source: SDK 8.0.400, VS 17.11.35303.130
Manifest Version: 8.2.0/8.0.100
Manifest Path: C:\Program Files\dotnet\sdk-manifests\8.0.100\microsoft.net.sdk.aspire\8.2.0\WorkloadManifest.json
Install Type: FileBased

Host:
Version: 8.0.8
Architecture: x64
Commit: 08338fcaa5

.NET SDKs installed:
8.0.400 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
Microsoft.AspNetCore.App 6.0.33 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.20 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 8.0.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 6.0.33 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.20 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 6.0.33 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 7.0.20 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 8.0.8 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found:
x86 [C:\Program Files (x86)\dotnet]
registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]

Environment variables:
Not set

### Anything else?

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.