Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MySQL/PosgreSQL: Index name on table is too long; the limit is 63 characters #9

Open
cure opened this issue May 6, 2011 · 0 comments

Comments

@cure
Copy link

cure commented May 6, 2011

Rails >= 3.0.3 aborts migrations if they try to create an index with a name are longer than 64 characters on PostgreSQL or MySQL (yes, 64, not 63 like the error says).

When acts_as_versioned creates indexes, it does not check the length of the resulting index name.

The patch below fixes that. It fixes the problem on MySQL and PostgreSQL (I tested both).

--- acts_as_versioned.rb    2011-05-06 11:37:30.000000000 -0400
+++ acts_as_versioned.rb    2011-05-06 11:29:47.000000000 -0400
@@ -440,7 +440,9 @@
                                          :precision => type_col.precision
             end
 
-            self.connection.add_index versioned_table_name, versioned_foreign_key
+            # Make sure not to create an index that is too long (postgres limits index names to 64 characters)
+            name = 'index_' + versioned_table_name + '_on_' + versioned_foreign_key
+            self.connection.add_index versioned_table_name, versioned_foreign_key, :name => name[0,63]
           end
 
           # Rake migration task to drop the versioned table
cure added a commit to cure/acts_as_versioned that referenced this issue Jun 19, 2011
…ersioned:

  technoweenie#4
  technoweenie#4
  MySQL decimal Datatype Requires Migration With ":precision => ..."
  to Avoid "No integer type has byte size " Error

  technoweenie#9
  technoweenie#9
  MySQL/PosgreSQL: Index name on table is too long; the limit is 63 characters
mjsommer pushed a commit to mjsommer/acts_as_versioned that referenced this issue Apr 18, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant