ActiveRecord::StatementInvalid: OCIError: ORA-00955: name is already used by an existing object

Viewed 77

I am getting this error while running active storage migration.

ActiveRecord::StatementInvalid: OCIError: ORA-00955: name is already used by an existing object: CREATE TABLE "ACTIVE_STORAGE_BLOBS" ("ID" NUMBER(38) NOT NULL PRIMARY KEY, "KEY" VARCHAR2(255) NOT NULL, "FILENAME" VARCHAR2(255) NOT NULL, "CONTENT_TYPE" VARCHAR2(255), "METADATA" CLOB, "BYTE_SIZE" NUMBER(19) NOT NULL, "CHECKSUM" VARCHAR2(255) NOT NULL, "CREATED_AT" TIMESTAMP NOT NULL)

Here is the active storage Migration File that is using to create active storage blob and active storage attachments table

# This migration comes from active_storage (originally 20170806125915)
class CreateActiveStorageTables < ActiveRecord::Migration[5.2]
 def change
  create_table :active_storage_blobs do |t|
    t.string   :key,        null: false
    t.string   :filename,   null: false
    t.string   :content_type
    t.text     :metadata
    t.bigint   :byte_size,  null: false
    t.string   :checksum,   null: false
    t.datetime :created_at, null: false

    t.index [ :key ], unique: true
  end

  create_table :active_storage_attachments do |t|
    t.string     :name,     null: false
    t.references :record,   null: false, polymorphic: true, index: false
    t.references :blob,     null: false

    t.datetime :created_at, null: false

    t.index [ :record_type, :record_id, :name, :blob_id ], name: "index_active_storage_attachments_uniqueness", unique: true
    t.foreign_key :active_storage_blobs, column: :blob_id
  end
 end
end

System configuration

Rails version: 5.2.0
activerecord-oracle_enhanced-adapter: 5.2.0 
ruby-oci8: 2.2.6.1
Ruby version: 2.6.0
Oracle Database version: 10.2.0.1.0
1 Answers

Error says that object (not necessarily table) whose name is ACTIVE_STORAGE_BLOB already exists in that schema.

What to do? First find out what it really is by querying

select * from user_objects where object_name = 'ACTIVE_STORAGE_BLOB';

Then decide what to do:

  • maybe you'll do nothing and continue using existing object
  • maybe you'll have to rename table you're trying to create. Or,
  • maybe you'll drop existing object so that you could create the table.

It depends on what you'll find out.

Related