dotnet / ef6

This is the codebase for Entity Framework 6 (previously maintained at https://entityframework.codeplex.com). Entity Framework Core is maintained at https://github.com/dotnet/efcore.
https://docs.microsoft.com/ef/ef6
MIT License
1.43k stars 545 forks source link

Composite Key Identifier Name too long #570

Closed 123wowow123 closed 2 years ago

123wowow123 commented 6 years ago

Error Message Executing "Update-Database -Verbose"

Identifier name 'IX_CampaignSetting_CampaignId_CampaignSetting_SettingTypeType_CampaignSetting_CampaignJourneyId_Camp' is too long

The k.HasName("IX_CampaignSettingClustered") Lamda seems to be ignored and EF generates a Identifier Name for the composite key that is too long for MySQL 'IX_CampaignSetting_CampaignId_CampaignSetting_SettingTypeType_CampaignSetting_CampaignJourneyId_Camp'

Relevant Code:

modelBuilder.Entity<CampaignSetting>()
                .HasKey(t => new
                {
                    t.CampaignId,
                    t.SettingTypeType,
                    t.CampaignJourneyId,
                    t.LanguageCode,
                    t.SettingKey
                }, k => k.HasName("IX_CampaignSettingClustered"))
    .Property(t => t.Id)
    .IsRequired();
create table `AuditLogs` (`AuditID` int not null  auto_increment ,`EntityName` longtext not null ,`PrimaryKeyJson` longtext not null ,`ChangeType` longtext not null ,`BeforeJson` longtext not null ,`AfterJson` longtext not null ,`User` longtext not null ,`AuditDateUTC` datetime not null ,primary key ( `AuditID`) ) engine=InnoDb auto_increment=0
create table `Campaigns` (`Id` nvarchar(36)  not null ,`CampaignUniqueId` longtext,`CampaignName` longtext,`CompanyName` longtext,`Country` longtext,`Theater` longtext,`CampaignSource` longtext,`IsDefault` bool not null ,`CreatedBy` longtext,`UpdatedBy` longtext,`Status` int not null ,`CreatedOn` datetime not null ,`UpdatedOn` datetime not null ,primary key ( `Id`) ) engine=InnoDb auto_increment=0
CREATE UNIQUE index  `IX_Id` on `Campaigns` (`Id` DESC) using HASH
create table `CampaignJourneys` (`CampaignId` nvarchar(36)  not null ,`JourneyId` nvarchar(36)  not null ,`CreatedBy` longtext,`UpdatedBy` longtext,`Status` int not null ,`Id` nvarchar(36)  not null ,`CreatedOn` datetime not null ,`UpdatedOn` datetime not null ,`CampaignSetting_CampaignId` nvarchar(36)  not null ,`CampaignSetting_SettingTypeType` nvarchar(50)  not null ,`CampaignSetting_CampaignJourneyId` nvarchar(72)  not null ,`CampaignSetting_LanguageCode` nvarchar(5)  not null ,`CampaignSetting_SettingKey` nvarchar(50)  not null ,primary key ( `CampaignId`,`JourneyId`) ) engine=InnoDb auto_increment=0
CREATE index  `IX_CampaignId` on `CampaignJourneys` (`CampaignId` DESC) using HASH
CREATE index  `IX_JourneyId` on `CampaignJourneys` (`JourneyId` DESC) using HASH
CREATE UNIQUE index  `IX_Id` on `CampaignJourneys` (`Id` DESC) using HASH
CREATE index  `IX_CampaignSetting_CampaignId_CampaignSetting_SettingTypeType_CampaignSetting_CampaignJourneyId_CampaignSetting_LanguageCode_Cam` on `CampaignJourneys` (`CampaignSetting_CampaignId` DESC,`CampaignSetting_SettingTypeType` DESC,`CampaignSetting_CampaignJourneyId` DESC,`CampaignSetting_LanguageCode` DESC,`CampaignSetting_SettingKey` DESC) using HASH
MySql.Data.MySqlClient.MySqlException (0x80004005): Identifier name 'IX_CampaignSetting_CampaignId_CampaignSetting_SettingTypeType_CampaignSetting_CampaignJourneyId_Camp' is too long
   at MySql.Data.MySqlClient.MySqlStream.ReadPacket()
   at MySql.Data.MySqlClient.NativeDriver.GetResult(Int32& affectedRow, Int64& insertedId)
   at MySql.Data.MySqlClient.Driver.GetResult(Int32 statementId, Int32& affectedRows, 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 System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.<NonQuery>b__0(DbCommand t, DbCommandInterceptionContext`1 c)
   at System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch[TTarget,TInterceptionContext,TResult](TTarget target, Func`3 operation, TInterceptionContext interceptionContext, Action`3 executing, Action`3 executed)
   at System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.NonQuery(DbCommand command, DbCommandInterceptionContext interceptionContext)
   at System.Data.Entity.Internal.InterceptableDbCommand.ExecuteNonQuery()
   at System.Data.Entity.Migrations.DbMigrator.ExecuteSql(MigrationStatement migrationStatement, DbConnection connection, DbTransaction transaction, DbInterceptionContext interceptionContext)
   at System.Data.Entity.Migrations.Infrastructure.MigratorLoggingDecorator.ExecuteSql(MigrationStatement migrationStatement, DbConnection connection, DbTransaction transaction, DbInterceptionContext interceptionContext)
   at System.Data.Entity.Migrations.DbMigrator.ExecuteStatementsInternal(IEnumerable`1 migrationStatements, DbConnection connection, DbTransaction transaction, DbInterceptionContext interceptionContext)
   at System.Data.Entity.Migrations.DbMigrator.ExecuteStatementsWithinTransaction(IEnumerable`1 migrationStatements, DbTransaction transaction, DbInterceptionContext interceptionContext)
   at System.Data.Entity.Migrations.DbMigrator.ExecuteStatementsWithinNewTransaction(IEnumerable`1 migrationStatements, DbConnection connection, DbInterceptionContext interceptionContext)
   at System.Data.Entity.Migrations.DbMigrator.ExecuteStatementsInternal(IEnumerable`1 migrationStatements, DbConnection connection, DbInterceptionContext interceptionContext)
   at System.Data.Entity.Migrations.DbMigrator.ExecuteStatementsInternal(IEnumerable`1 migrationStatements, DbConnection connection)
   at System.Data.Entity.Migrations.DbMigrator.<>c__DisplayClass32.<ExecuteStatements>b__30()
   at System.Data.Entity.Infrastructure.DefaultExecutionStrategy.Execute(Action operation)
   at System.Data.Entity.Migrations.DbMigrator.ExecuteStatements(IEnumerable`1 migrationStatements, DbTransaction existingTransaction)
   at System.Data.Entity.Migrations.DbMigrator.ExecuteStatements(IEnumerable`1 migrationStatements)
   at System.Data.Entity.Migrations.Infrastructure.MigratorBase.ExecuteStatements(IEnumerable`1 migrationStatements)
   at System.Data.Entity.Migrations.DbMigrator.ExecuteOperations(String migrationId, VersionedModel targetModel, IEnumerable`1 operations, IEnumerable`1 systemOperations, Boolean downgrading, Boolean auto)
   at System.Data.Entity.Migrations.DbMigrator.ApplyMigration(DbMigration migration, DbMigration lastMigration)
   at System.Data.Entity.Migrations.Infrastructure.MigratorLoggingDecorator.ApplyMigration(DbMigration migration, DbMigration lastMigration)
   at System.Data.Entity.Migrations.DbMigrator.Upgrade(IEnumerable`1 pendingMigrations, String targetMigrationId, String lastMigrationId)
   at System.Data.Entity.Migrations.Infrastructure.MigratorLoggingDecorator.Upgrade(IEnumerable`1 pendingMigrations, String targetMigrationId, String lastMigrationId)
   at System.Data.Entity.Migrations.DbMigrator.UpdateInternal(String targetMigration)
   at System.Data.Entity.Migrations.DbMigrator.<>c__DisplayClasse.<Update>b__d()
   at System.Data.Entity.Migrations.DbMigrator.EnsureDatabaseExists(Action mustSucceedToKeepDatabase)
   at System.Data.Entity.Migrations.Infrastructure.MigratorBase.EnsureDatabaseExists(Action mustSucceedToKeepDatabase)
   at System.Data.Entity.Migrations.DbMigrator.Update(String targetMigration)
   at System.Data.Entity.Migrations.Infrastructure.MigratorBase.Update(String targetMigration)
   at System.Data.Entity.Migrations.Design.ToolingFacade.UpdateRunner.RunCore()
   at System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.Run()
Identifier name 'IX_CampaignSetting_CampaignId_CampaignSetting_SettingTypeType_CampaignSetting_CampaignJourneyId_Camp' is too long

Package.config references

  <package id="EntityFramework" version="6.2.0" targetFramework="net452" />
  <package id="MySql.Data" version="6.9.12" targetFramework="net452" />
  <package id="MySql.Data.Entity" version="6.9.12" targetFramework="net452" />
  <package id="System.Runtime.InteropServices.RuntimeInformation" version="4.0.0" targetFramework="net452" />
ajcvickers commented 2 years ago

This issue has been closed because EF6 is no longer being actively developed. We are instead focusing on stability of the codebase, which means we will only make changes to address security issues. See the repo README for more information.