Rails, ORA-000972 and you

Lately 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
    create_table  do |t|
      t.string 
      t.references 
    end
  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
    create_table  do |t|
      t.string 
      t.references 
    end
  end
  ...
end

Then in your model use the shorter foreign key name.


class LongTable < ActiveRecord::Base
  belongs_to ,
              => 'ClassName',
              => '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.

Copyright © Tim McGilchrist 2007-2024
Powered by Hakyll