SQL type for string has changed after v3.*
See original GitHub issueHi team,
A lot of appreciation to your work. Thanks a lot for this great package.
The issue
Some time ago I have started work in one opensource project. First PR is bump the project and dependencies from .NET Core 3.1 to .NET 6.
The project is a package manager and it supports different DBs, using EF Core as ORM & code-first approach.
So at stable versions there is a Pomelo.EntityFrameworkCore.MySql v3.1.0
Now I’m trying to use Pomelo.EntityFrameworkCore.MySql v6.0.0
And it seems like some type mapping logic has changed. The problem is in a strings with a large length (e.g. 4000 symbols)
When I have launched EF migrations on a 3.1 they use longtext
MySQL type for this fields.
CREATE TABLE `Packages` (
`Key` int NOT NULL AUTO_INCREMENT,
`Id` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,
`Authors` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL,
`Description` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL,
`Downloads` bigint NOT NULL,
`HasReadme` tinyint(1) NOT NULL,
`Language` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
`Listed` tinyint(1) NOT NULL,
`MinClientVersion` varchar(44) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
`Published` datetime(6) NOT NULL,
`RequireLicenseAcceptance` tinyint(1) NOT NULL,
`Summary` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL,
`Title` varchar(256) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
`IconUrl` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL,
`LicenseUrl` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL,
`ProjectUrl` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL,
`RepositoryUrl` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL,
`RepositoryType` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
`Tags` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL,
`RowVersion` timestamp(6) NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
`Version` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,
`IsPrerelease` tinyint(1) NOT NULL DEFAULT 0,
`SemVerLevel` int NOT NULL DEFAULT 0,
`OriginalVersion` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
`ReleaseNotes` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL,
`HasEmbeddedIcon` tinyint(1) NOT NULL DEFAULT 0,
...
);
Now on 6.0 it uses varchar(...)
as a type:
CREATE TABLE `Packages` (
`Key` int NOT NULL AUTO_INCREMENT,
`Id` varchar(128) NOT NULL,
`Authors` varchar(4000) NULL,
`Description` varchar(4000) NULL,
`Downloads` bigint NOT NULL,
`HasReadme` tinyint(1) NOT NULL,
`Language` varchar(20) NULL,
`Listed` tinyint(1) NOT NULL,
`MinClientVersion` varchar(44) NULL,
`Published` datetime(6) NOT NULL,
`RequireLicenseAcceptance` tinyint(1) NOT NULL,
`Summary` varchar(4000) NULL,
`Title` varchar(256) NULL,
`IconUrl` varchar(4000) NULL,
`LicenseUrl` varchar(4000) NULL,
`ProjectUrl` varchar(4000) NULL,
`RepositoryUrl` varchar(4000) NULL,
`RepositoryType` varchar(100) NULL,
`Tags` varchar(4000) NULL,
`RowVersion` datetime(6) NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
`Version` varchar(64) NOT NULL,
...
);
Which causes the next error
Row size too large. The maximum row size for the used table type, not counting BLOBs, is 65535. This includes storage overhead, check the manual. You have to change some columns to TEXT or BLOBs
So the questions are:
- In which release this behavior was changed?
- How I could manage the target type to avoid this situation? (I’ve tried
HasColumnType(longtext)
, but had no success)
Configuration info
Further technical details
MySQL version: MySQL Ver 8.0.27 for Linux on x86_64 (MySQL Community Server - GPL)
Operating system: Win10 Build 19044.1466 & Docker version 20.10.12, build e91ed57
Pomelo.EntityFrameworkCore.MySql version: 6.0.0
Thanks in advance!
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:6
@lauxjpn thanks a lot for your explanation. It became completely clear for me
In case you cannot do this, because other supported providers cannot deal with this, you might want to do those changes only for Pomelo.
A simple way to do this is to check the provider and then change the model as needed at the end of the
OnModelCreating
method:Applying this to my sample code results in the following
CREATE TABLE
statement: