Reputation: 129
I am trying to run a rails migration and I am seeing the error "BLOB/TEXT column used in key specification without a key length"... However, I'm specifying the length in the migration class. Rails seems to ignore this when generating the SQL statement from the migration. Any clues?
Here's my migration class:
class AddIndexToAccounts < ActiveRecord::Migration
def self.up
add_index :TACCOUNT, :NAMEX, :length => 5
end
def self.down
remove_index :TACCOUNT, :NAMEX
end
end
And here's the error output. It seems to have seen the length specification, but it's not present in the SQL statement that it generates:
** [out :: 192.168.10.7] -- add_index(:TACCOUNT, :NAMEX, {:length=>5})
** [out :: 192.168.10.7] rake aborted!
** [out :: 192.168.10.7] An error has occurred, all later migrations canceled:
** [out :: 192.168.10.7]
** [out :: 192.168.10.7] Mysql::Error: BLOB/TEXT column 'NAMEX' used in key specification without a key length: CREATE INDEX `index_TACCOUNT_on_NAMEX` ON `TACCOUNT` (`NAMEX`)
Upvotes: 7
Views: 7571
Reputation: 211560
You could try being more specific to see if that tricks it into working:
add_index :TACCOUNT, :NAMEX, :length => { :NAMEX => 5 }
As a last resort you can crete the index the "hard way" using SQL directly by adjusting the incorrect ADD INDEX
statement and using execute
on the correct one.
Upvotes: 13