-
Notifications
You must be signed in to change notification settings - Fork 386
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Scaffolding fails: "The annotation 'MySql:IndexPrefixLength' cannot be added because an annotation with the same name already exists." #1189
Comments
The interesting thing is that |
I have created a new project but the result was the same. |
Could it be related to this: dotnet/efcore#11846 ? |
Can you isolate it to a certain table w/ the Tables option? If so, please share the schema of the table. |
I can confirm, that the moment two indices are used for the same column, and both are using a prefix length, I can reproduce the exception: CREATE TABLE `Test` (
`TestId` int NOT NULL AUTO_INCREMENT,
`LongString` varchar(12000) DEFAULT NULL,
PRIMARY KEY (`TestId`),
KEY `IX_LongString` (`LongString`(120)),
KEY `IX_LongString2` (`LongString`(100))
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; Scaffold command:
Output:
|
Great, that is useful information! |
I don't think SQL Server uses index prefixes at all. I guess you must have converted the MSSQL database somehow to MySQL. In the conversion process, the index prefixes must have been added (which should be correct). The issue are not the index prefixes themselves, but annotations that are being set for those prefixes by us for the index. Because of dotnet/efcore#11846 you referenced above (an EF Core bug), indices with the same set of columns are being merged by EF Core into one index. But then, setting the same annotation again, from the second database index to the merged EF Core index, throws an exception. We implemented a workaround for this with #1190. |
Scaffolding existing DB that was successfully scaffolded using MS package in same project:
Scaffold-DbContext "server=localhost;user=user;password=password;database=mysql_db" "Pomelo.EntityFrameworkCore.MySql" -OutputDir EF
The process ends pretty much immiediately with exception and stacktrace below.
Exception message
System.InvalidOperationException: The annotation 'MySql:IndexPrefixLength' cannot be added because an annotation with the same name already exists.
Stack trace
Further technical details
MySQL version: 5.7.18
Operating system: Windows 10
Pomelo.EntityFrameworkCore.MySql version: 3.2.2
Microsoft.AspNetCore.App version: 3.1
The text was updated successfully, but these errors were encountered: