ActiveRecord::StatementInvalid: OCIError: ORA-00955:名称已被现有对象



在运行活动存储迁移时出现此错误。

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)

下面是用于创建活动存储blob和活动存储附件表的活动存储迁移文件

# 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

系统配置

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

错误提示对象(不一定是)名称为ACTIVE_STORAGE_BLOB的表在该模式中已经存在。

该怎么办?首先通过查询

找出它到底是什么
select * from user_objects where object_name = 'ACTIVE_STORAGE_BLOB';

然后决定怎么做:

  • 也许你什么都不做继续使用现有的对象
  • 可能需要重命名要创建的表。或者,
  • 也许你会放弃现有的对象,这样你就可以创建表。

这取决于你会发现什么。

最新更新