This project is archived and is in readonly mode.

#3508 ✓duplicate
Nathaniel Bibler

Limit MySQL index name length

Reported by Nathaniel Bibler | November 24th, 2009 @ 02:49 PM

The current MySQL adapter allows you to define new indices on a table with names that are generated beyond the allowed 50 byte length constraint:

add_index :posts, [:user_id, :a_long_column_name_that_concats_beyond_50]
# => "posts_on_user_id_and_a_long_column_name_that_concats_beyond_50"

This is an issue in a an environment where multiple databases are used in development vs production (sqlite vs postgresql vs mysql). Sqlite3 and PostgreSQL allow indices with longer names and therefore do not cause issue. But when MySQL is added, this problem may easily - and suddenly - show up.

Perhaps a logical truncation of the generated index name is appropriate in this case? Either way, since it is still around and hasn't been raised in Lighthouse, I thought it might be worth a revisit.

This issue was originally raised as ticket #10954 in Trac, two years ago by lesgrumels. It appears to still be an issue up to and through Rails 2.3.4.

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Referenced by

Pages