1

I am getting "Specified key was too long; max key length is 1000 bytes" on my server. I have the following (if i miss off a tag its just poor copy and paste.

<configuration>
  <configSections>
  <configSections>
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=xxxxx" requirePermission="false" />
  </configSections>
  <connectionStrings>
    <add name="ArticleContext" providerName="MySql.Data.MySqlClient" connectionString="server=xxxxxxxx; Port=xxxx; database=xxxxxx; User Id=xxxxxx; Pwd=xxxxx" />
</connectionStrings>

  <system.web>
<httpRuntime targetFramework="4.5" />
    </system.web>

 <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">

and further down

<entityFramework>
    <contexts>
      <context type="EverythingASP.DAL.ArticleContext, EverythingASP">
        <databaseInitializer type="EverythingASP.DAL.Initializer, EverythingASP" />
      </context>
    </contexts>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="v11.0" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
      <provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6, Version=6.9.5.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d">
      </provider>
    </providers>
  </entityFramework>
<system.data>
    <DbProviderFactories>
      <remove invariant="MySql.Data.MySqlClient" />
      <add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.9.5.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
    </DbProviderFactories>
  </system.data>

Any ideas what to look for? I dont even know what key it's referring to. When googling the only answers were with regards to migrations, and I don't have any in this as far as I'm aware.

Update #1

All entities have Ids assigned automatically by EF when they are created. This error is persisting on startup! The ids are all defined for the entities I have as:

[Key]
public int Id { get; set; }

So at run-time the max key value is 28...

Is this an issue with EF6 and mysql ?

Fred Johnson
  • 2,539
  • 3
  • 26
  • 52
  • The error refers to an index on a table, where the width of the indexed columns potentially [exceeds 1000 bytes](http://stackoverflow.com/q/8746207/314291). It looks like you are using code first EF, so have a look for `Index` attributes on your entities, or in the Fluent configuration. – StuartLC Jan 07 '15 at 19:29
  • i dont see how though, this is on startup of my application and I'm adding data like this: JSArticle js = new JSArticle("Comments", "beg", 1, "comments", Difficulty.Beginner); context.JSArchive.Add(js); context.SaveChanges(); so basically, my longest string being added is around 15ish characters... – Fred Johnson Jan 07 '15 at 19:31
  • One more thought - if I remember correctly, EF will assume all columns make up the primary key of a table if there is no PK explicitly defined. Have a look through your entities / Fluent config to make sure everything has either a PK or at least a convention-named Id / TableId etc. – StuartLC Jan 07 '15 at 19:35
  • have: public int Id { get; set; } under every entity (there's not many thankfully! :) ) – Fred Johnson Jan 07 '15 at 19:39
  • In your web.config, you don't have any really long AppSettings names do you? – Tommy Jan 07 '15 at 20:31
  • nope :( noticed there's a migration automatically added in with mySql. So it makes the table and I've read there's a known bug with myISAM so having a look into fixing this now – Fred Johnson Jan 07 '15 at 20:41

1 Answers1

0

The answer was to change the storage engine from myisam to innodb. This can be done in script, or if you are using godaddy, go on each of the tables and theres a button in the columns. dont ring support, they dont even know what it is.

Fred Johnson
  • 2,539
  • 3
  • 26
  • 52