Rails, ORA-000972 and you
June 24, 2011Lately I’ve been running up against “ORA-00972: identifier is too long”, when writing Rails migrations for Oracle. This particular error indicates that one of your identifiers is longer than 32 characters which is the maximum length for Oracle.
It’ll look something like this in your code:
class CreateLongTable < ActiveRecord::Migration
def self.up
:long_table do |t|
create_table .string :title
t.references :someother_really_long_identifier
tend
end
...
end
This migration will give you a foreign key id called someother_really_long_identifier_id which is obviously too long for Oracle. The solution is to use your own foreign key id name. In your migration add a shorter reference.
class CreateLongTable < ActiveRecord::Migration
def self.up
:long_table do |t|
create_table .string :title
t.references :short_name
tend
end
...
end
Then in your model use the shorter foreign key name.
class LongTable < ActiveRecord::Base
:someother_really_long_identifier,
belongs_to :class_name => 'ClassName',
:foreign_key => 'short_name_id'
end
And everything should be sweet, your model will use someother_really_long_identifier and no-one need know that the table is really using short_name_id.