This project is archived and is in readonly mode.

#734 ✓wontfix
Jonathan Weiss

Add support for index length in MySQL adapter and schema dumper

Reported by Jonathan Weiss | August 14th, 2008 @ 09:07 AM | in 2.x

Add support for index length in MySQL adapter and schema dumper.

Using this patch you can now define a length for you indices:

add_index(:people, :col_name, :length => 5) add_index(:people, [:col_name, :other_col], :length => {:col_name => 5, :other_col => 1})

This will result in the following SQL:

CREATE INDEX index_people_on_col_name ON people (col_name(5)) CREATE INDEX index_people_on_col_name ON people (col_name(5), other_col(1))

The schema dumper will honor the index length so that schema.rb will be correct and keep track of index length.


Or the attached patch.

Provided by Christoph Bünte (, Enno Brehm ( Jonathan Weiss (

Comments and changes to this ticket

  • Jonathan Weiss
  • Jonathan Weiss
  • Pratik

    Pratik October 7th, 2008 @ 03:56 PM

    • Assigned user set to “Pratik”
    • State changed from “new” to “wontfix”

    I think this is a better fit for a plugin. I asked around and no one really ever needed to use this feature. Having said that, if you want Rails to provide any hooks for pluginizing this, patches will be most welcome.

    If you find people who need this feature, please have them post +1 here and we can re-evaluate the patch.


  • Ricky

    Ricky November 3rd, 2008 @ 07:25 AM

    +1 on this. This sort of thing seems to be required whenever you create an index on a blob-like field (text/binary/etc).

  • dkindlund

    dkindlund March 2nd, 2009 @ 10:06 PM

    1. Have you seen the plugin-version of this?

    Also, even though the plugin works, it fails to write the correct length information to the db/schema.rb file. So, when you run something like "rake tests:unit", then the corresponding db/schema.rb file loads but fails on the malformed index (i.e., "no length specified").

    So, if you use that plugin as a basis, is there any way to add the "db/schema.rb" creation logic to the plugin?

  • ...Paul

    ...Paul September 6th, 2009 @ 09:26 PM

    You can uncomment this line from config/environment.rb

    config.active_record.schema_format = :sql

    Then rake tests will clone_structure rather than just clone. Reference comment on Bug #74.

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=""></a>

People watching this ticket


Referenced by