Mysql key too long error

I’m using the acts as taggable on plugin, and in the migrations
there’s a line of code to create an index:

add_index :taggings, [:taggable_id, :taggable_type, :context], :name
=> “tagging_index”, :limit => {:name => 10, :surname => 20}

When I use unicode, the migration fails and I get told that the index
is too long and can only be 1000 bytes. I switched over to ascii to
see if I get the same problem and I didn’t. I really want to use
unicode, so I want to get this working.

I’m running Rails 3.0.7 with MySQL 5.1.

On Apr 23, 11:23pm, Mike C [email protected] wrote:

I’m using the acts as taggable on plugin, and in the migrations
there’s a line of code to create an index:

add_index :taggings, [:taggable_id, :taggable_type, :context], :name
=> “tagging_index”, :limit => {:name => 10, :surname => 20}

When I use unicode, the migration fails and I get told that the index
is too long and can only be 1000 bytes. I switched over to ascii to
see if I get the same problem and I didn’t. I really want to use
unicode, so I want to get this working.

If you want to limit the length of the prefix used for indexes, you’ll
need to change name/surname up there for the string columns you want
to index (ie taggable_type and context) and change the numbers as
appropriate to your data

Fred

How can I use the :limit to change taggable_ type and context?

On Apr 24, 12:32am, Frederick C. [email protected]

Oh, I was looking for an example of how to use it like a piece of code
or something.

On Apr 24, 7:51am, Frederick C. [email protected]

Nevermind, I got it. I just have to test to see if it works. Thanks
for your help!

On Apr 24, 9:23am, Mike C [email protected] wrote:

How can I use the :limit to change taggable_ type and context?

The limit tells mysql how much of the column to use for the index.
Pick values such that your total index length falls within the limit
(you’re probably better off picking a smaller value for taggable_type,
you’re very unlikely to have massively long values in that column)

Fred

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs