ruby-on-rails - ActiveRecord::StatementInvalid: OCIError: ORA-00955: name is already used by an existing object
问题描述
我在运行主动存储迁移时收到此错误。
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
解决方案
错误表示该模式中已经存在名称的对象(不一定是table )。ACTIVE_STORAGE_BLOB
该怎么办?首先通过查询找出它到底是什么
select * from user_objects where object_name = 'ACTIVE_STORAGE_BLOB';
然后决定做什么:
- 也许你什么也不做,继续使用现有的对象
- 也许您必须重命名您要创建的表。或者,
- 也许您会删除现有对象以便创建表。
这取决于你会发现什么。
推荐阅读
- angular - NativeScript:找不到工作区路径的工作区文件
- python - 将列表形式的字符串转换为整数列表
- git - 我们可以使用/提取一个程序的提交到另一个类似的程序吗?
- javascript - MVC - 如何在 JS 中更新模型后更新视图
- ajax - 在 Laravel 8 中使用 DataTables 进行 Elasticsearch
- docker - 如何为私有应用程序创建私有 solana 网络
- java - Eclipse 动态 Web 项目忽略 webapp/WEB-INF/lib 下的 jar
- android-recyclerview - 我想将recyclerview的项目添加到可刷卡中
- laravel - Laravel HasMany 与参数的关系
- conan - 生成锁文件时无法指定名称和版本