microsoft / microsoft/aspire

Unable to add a migration with Aspire.Pomelo.EntityFrameworkCore.MySql

Open
#8,090 19 comments 0 reactions 0 assignees View on GitHub
area-integrations entityframework
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

I downloaded the sample Aspire project at https://github.com/MicrosoftDocs/aspire-docs-samples/ and ran it. It worked just fine. I then added a migration as per the tutorial at [this page](https://learn.microsoft.com/en-us/dotnet/aspire/database/ef-core-migrations) (i.e. with the commands `cd .\SupportTicketApi.Api` and `dotnet ef migrations add InitialCreate --project ..\SupportTicketApi.Data\SupportTicketApi.Data.csproj`), and this worked just fine as well.

I then deleted the project and downloaded it again. This time, before adding a migration, I went around the project and changed all references to SqlServer to MySql. In particular:

- I replaced the NuGet package `Aspire.Hosting.SqlServer` with `Aspire.Hosting.MySql` in all the projects where it was referenced (AppHost)
- I replaced the NuGet package `Aspire.Microsoft.EntityFrameworkCore.SqlServer` with `Aspire.Pomelo.EntityFrameworkCore.MySql` in all the rpojects where it was referenced (Api, AppHost, Data)
- In the AppHost project, I replaced the `AddSqlServer` function call with `AddMySql`, without changing any of the parameters
- In the Api project, I replaced the `AddSqlServerDbContextˋ function call with `AddMySqlDbContext`, without changing any of the parameters

I then built and ran the application without issues.

At this point, I tried creating a migration with the same command as before. However, this time I got an error:
```
The exception 'Host 'DESKTOP-' is not allowed to connect to this MySQL server' was thrown while attempting to find 'DbContext' types. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728
```

### Expected Behavior

The migration should be correctly added for MySQL just like it is for SqlServer.

### Steps To Reproduce

[Minimal project to reproduce](https://github.com/neos7m/MinimalReproduc-Issue-AspireMySql)

### Exceptions (if any)

```
info: Polly[3]
Execution attempt. Source: 'Microsoft.Extensions.Hosting.AspireEFMySqlExtensions.ServerVersion/(null)/Retry', Operation Key: '', Result: 'Host 'DESKTOP-' is not allowed to connect to this MySQL server', Handled: 'False', Attempt: '0', Execution Time: 43,2392ms
MySqlConnector.MySqlException (0x80004005): Host 'DESKTOP-' is not allowed to connect to this MySQL server
at MySqlConnector.Core.ServerSession.ReceiveReplyAsync(IOBehavior ioBehavior, CancellationToken cancellationToken) in /_/src/MySqlConnector/Core/ServerSession.cs:line 894
at MySqlConnector.Core.ServerSession.ConnectAsync(ConnectionSettings cs, MySqlConnection connection, Int64 startingTimestamp, ILoadBalancer loadBalancer, Activity activity, IOBehavior ioBehavior, CancellationToken cancellationToken) in /_/src/MySqlConnector/Core/ServerSession.cs:line 445
at MySqlConnector.MySqlConnection.CreateSessionAsync(ConnectionPool pool, Int64 startingTimestamp, Activity activity, Nullable`1 ioBehavior, CancellationToken cancellationToken) in /_/src/MySqlConnector/MySqlConnection.cs:line 932
at MySqlConnector.MySqlConnection.CreateSessionAsync(ConnectionPool pool, Int64 startingTimestamp, Activity activity, Nullable`1 ioBehavior, CancellationToken cancellationToken) in /_/src/MySqlConnector/MySqlConnection.cs:line 938
at MySqlConnector.MySqlConnection.OpenAsync(Nullable`1 ioBehavior, CancellationToken cancellationToken) in /_/src/MySqlConnector/MySqlConnection.cs:line 419
at MySqlConnector.MySqlConnection.Open() in /_/src/MySqlConnector/MySqlConnection.cs:line 381
at Microsoft.EntityFrameworkCore.ServerVersion.AutoDetect(String connectionString)
at Microsoft.Extensions.Hosting.AspireEFMySqlExtensions.<>c__2`1.b__2_5(String cs) in /_/src/Components/Aspire.Pomelo.EntityFrameworkCore.MySql/AspireEFMySqlExtensions.cs:line 108
at Polly.ResiliencePipeline.<>c__36`2.b__36_0(ResilienceContext _, ValueTuple`2 state)
The exception 'Host 'DESKTOP-' is not allowed to connect to this MySQL server' was thrown while attempting to find 'DbContext' types. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728
```

### .NET Version info

.NET version 9.0.201

### Anything else?

Aspire version 9.1.0
Docker version 28.0.1 (fresh install)
Visual Studio 2022 version 17.13.3
`dotnet-ef` tool version 9.0.3

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.