| Bug #106592 | Unable to do Entity Framework Core Migration after migrating to version 6.0.0 | ||
|---|---|---|---|
| Submitted: | 28 Feb 2022 6:08 | Modified: | 21 Jul 2022 5:49 |
| Reporter: | Gerard Ang | Email Updates: | |
| Status: | Verified | Impact on me: | |
| Category: | Connector / NET | Severity: | S3 (Non-critical) |
| Version: | 6.0.0+MySQL8.0.28 | OS: | Windows |
| Assigned to: | CPU Architecture: | Any | |
| Tags: | 6.0.0, C#, nuget | ||
[28 Feb 2022 6:08]
Gerard Ang
[3 Mar 2022 15:30]
Clint Andrews
Exception is thrown even if you remove all existing migrations and create a new initial migration.
[4 Mar 2022 2:03]
Gerard Ang
Hi Clint, Yes, the exception is still thrown even if I remove the contents of the Migration folder and do an Add-Migration for the new first initial migration.
[18 Apr 2022 3:24]
Gerard Ang
Anyone with any updates on this? I understand that .NET 5 EOL is coming up soon, so I am wondering if I should downgrade to a .NET Core 3.1 library, if there is no solution for it.
[18 Apr 2022 13:11]
Clint Andrews
We ended up migrating to Pomelo version of the nuget package. This did require some updates to the Context but migrations are working. I hope this gets addressed soon.
[21 Apr 2022 13:31]
MySQL Verification Team
Bug #107022 marked as duplicate of this one.
[5 Jul 2022 8:49]
Peter Kjaer
I am having the same issue and it's blocking the upgrade to .NET 6 for us. The only solution I have been able to find is switching to Pomelo...
[19 Jul 2022 17:42]
Patrick Allen
Is anybody working on this? Submitted 4.5 months ago and still "Analyzing"?
[21 Jul 2022 5:49]
MySQL Verification Team
Hello, Thank you for the bug report and feedback. Verified as described. Regards, Ashwini Patil
[16 Aug 2022 9:44]
Adam Croot
This issue has been blocking me for weeks now, so I did some investigation, and this seems to workaround/fix the issue. Add this as a DesignTimeService.
public class MysqlEntityFrameworkDesignTimeServices : IDesignTimeServices
{
public void ConfigureDesignTimeServices(IServiceCollection serviceCollection)
{
serviceCollection.AddEntityFrameworkMySQL();
new EntityFrameworkRelationalDesignServicesBuilder(serviceCollection)
.TryAddCoreServices();
}
}
The key to this is the TryAddCoreServices(). Looking at the documentation of EntityFrameworkRelationalDesignServicesBuilder: https://docs.microsoft.com/en-us/dotnet/api/microsoft.entityframeworkcore.design.entityfra...
It was introduced in 6.0 and the notes say this:
> Providers should create an instance of this class, use its methods to register services, and then call TryAddCoreServices() to fill out the remaining Entity Framework services.
Looking in the source, I don't see any use of EntityFrameworkRelationalDesignServicesBuilder
Maybe this is why?
Few notes:
1) I don't fully understand EF enough to know why this "fixes" the issue but I referenced this issue: https://github.com/FirebirdSQL/NETProvider/issues/1025
2) The first migration that worked with the above, generated a migration where it wanted to change all of my "text" (string) fields to longtext as below
migrationBuilder.AlterColumn<string>(
name: "Name",
table: "Table",
type: "longtext",
nullable: true,
oldClrType: typeof(string),
oldType: "text",
oldNullable: true);
I don't know if this is to be expected or what caused this.
3) FWIW, The error is also reproducible using the context's in the tests
Your mileage may vary; I need to check what happened in point 2. Does anybody know if this was by design? These properties were just declared as below, so I assume this is by design, but I can't find a release note mentioning it.
public string Name { get; set; }
Adam
