Open HengzheLi opened 6 years ago
Dev branch?
Yes
Does this mean that the length of the DisplayAlias column should be restricted to 255 characters?
Or not index this field on mysql
OK, so a generic solution might be that SchemeBuilder.CreateIndex ignores columns longer than 255 characters for MySQL databases.
@HengzheLi which MySQL version are you using?
@sebastienros there are some deeper issues here: It seems that we have migrations in the built-in features that create indices on columns that cause problems in different database engines (and engine versions), SQL Server included.
Index size limits:
The MySQL command interpreter modifies the create index
command so that values will be trimmed if the character length is over 767, so I suspect that @HengzheLi is using an earlier version where this limit is much lower. Anyway, this logic does not handle clustered indices, so the setup fails on the latest engine version on another migration.
The SQL Server command interpreter does not have this check, so you won't see setup errors, but a runtime error can easily be triggered: AutoroutePartRecord.DisplayAlias
allows 2048 characters, but saving a content item with a Title over 450 or 850 characters will fail to save because of the index.
So the migrations and index creations have to be retroactively modified and tested, but we need to figure out what limitations should we apply.
@HengzheLi which MySQL version are you using?
@BenedekFarkas I used version 5.7
Ran into this as well with 1.10.3...
at System.RuntimeMethodHandle.InvokeMethod(Object t2022-02-09 16:33:04,235 [15] Orchard.Data.Migration.DataMigrationManager - Default - Error while running migration version 0 for Orchard.Recipes. [removed] System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> MySql.Data.MySqlClient.MySqlException: Specified key was too long; max key length is 3072 bytes at MySql.Data.MySqlClient.MySqlStream.ReadPacket() at MySql.Data.MySqlClient.NativeDriver.GetResult(Int32& affectedRow, Int64& insertedId) at MySql.Data.MySqlClient.Driver.NextResult(Int32 statementId, Boolean force) at MySql.Data.MySqlClient.MySqlDataReader.NextResult() at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior) at MySql.Data.MySqlClient.MySqlCommand.ExecuteNonQuery() at Orchard.Data.Migration.Interpreters.DefaultDataMigrationInterpreter.RunPendingStatements() in C:\Agent2\work\ORCH-Release\src\Orchard\Data\Migration\Interpreters\DefaultDataMigrationInterpreter.cs:line 380 at Orchard.Data.Migration.Interpreters.DefaultDataMigrationInterpreter.ExecuteCustomInterpreter[T](T command) in C:\Agent2\work\ORCH-Release\src\Orchard\Data\Migration\Interpreters\DefaultDataMigrationInterpreter.cs:line 398 at Orchard.Data.Migration.Interpreters.DefaultDataMigrationInterpreter.Visit(StringBuilder builder, AddIndexCommand command) in C:\Agent2\work\ORCH-Release\src\Orchard\Data\Migration\Interpreters\DefaultDataMigrationInterpreter.cs:line 227 at Orchard.Data.Migration.Interpreters.DefaultDataMigrationInterpreter.Visit(AlterTableCommand command) in C:\Agent2\work\ORCH-Release\src\Orchard\Data\Migration\Interpreters\DefaultDataMigrationInterpreter.cs:line 153 at Orchard.Data.Migration.Schema.SchemaBuilder.AlterTable(String name, Action1 table) in C:\Agent2\work\ORCH-Release\src\Orchard\Data\Migration\Schema\SchemaBuilder.cs:line 58 at Orchard.Recipes.Migrations.Create() --- End of inner exception stack trace --- at System.RuntimeMethodHandle.InvokeMethod(Object t
Running Percona 5.7.36-39, which is MySQL 5.7.37.
Create a new tenant using mysql as database. Occur below error while setting it up
Got the sql from vs debugger, it is:
create index
fy_IDX_AutoroutePartRecord_DisplayAliason
fy_Orchard_Autoroute_AutoroutePartRecord(DisplayAlias(767))
From SO answer https://stackoverflow.com/questions/1814532/1071-specified-key-was-too-long-max-key-length-is-767-bytes/31474509#31474509. I guess may be
create index
fy_IDX_AutoroutePartRecord_DisplayAliason
fy_Orchard_Autoroute_AutoroutePartRecord(DisplayAlias(255))
can work