Rails 在 Oracle 数据库上 table 名称超过 30 个字符,Globalize 找不到我的 table
Rails on Oracle database with table name over 30 characters long and Globalize can't find my table
我正在移植 MySQL 数据库,我想迁移到 Oracle DB 12cRC2。问题是我的一些 table 的名字超过了 30 个字符。
一切正常(在弄乱了我的 schema.rb 文件之后)。
我正在使用 "Globalize" gem 来本地化我的数据库。
当我 运行 我的种子时,我的翻译出现了错误 table,比如:
OCIError: ORA-04043: object "aaaaaaaa_bbbbb_cccc_translations" does not exist
但是当我使用 sqlplus 时,我可以看到我的 table 没问题...使用 DESC 或 SELECT 查询。
我用的是oracle-instantclient12.2连接
我怀疑 table 名称长度,因为其他 table 名称较小的名称不会引发 execption
我的堆栈:
rails aborted!
ActiveRecord::ConnectionAdapters::OracleEnhanced::ConnectionException: "DESC aaaaaaaa_bbbbb_cccc_translations" failed; does it exist?
/usr/local/bundle/gems/activerecord-oracle_enhanced-adapter-5.2.5/lib/active_record/connection_adapters/oracle_enhanced/oci_connection.rb:209:in `rescue in describe'
/usr/local/bundle/gems/activerecord-oracle_enhanced-adapter-5.2.5/lib/active_record/connection_adapters/oracle_enhanced/oci_connection.rb:202:in `describe'
/usr/local/bundle/gems/activerecord-oracle_enhanced-adapter-5.2.5/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb:552:in `pk_and_sequence_for'
/usr/local/bundle/gems/activerecord-oracle_enhanced-adapter-5.2.5/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb:585:in `primary_key'
/usr/local/bundle/gems/activerecord-5.2.2/lib/active_record/connection_adapters/schema_cache.rb:43:in `primary_keys'
/usr/local/bundle/gems/activerecord-5.2.2/lib/active_record/attribute_methods/primary_key.rb:100:in `get_primary_key'
/usr/local/bundle/gems/activerecord-5.2.2/lib/active_record/attribute_methods/primary_key.rb:87:in `reset_primary_key'
/usr/local/bundle/gems/activerecord-5.2.2/lib/active_record/attribute_methods/primary_key.rb:75:in `primary_key'
/usr/local/bundle/gems/activerecord-5.2.2/lib/active_record/associations/foreign_association.rb:6:in `foreign_key_present?'
/usr/local/bundle/gems/activerecord-5.2.2/lib/active_record/associations/association.rb:203:in `find_target?'
/usr/local/bundle/gems/activerecord-5.2.2/lib/active_record/associations/collection_association.rb:272:in `load_target'
/usr/local/bundle/gems/activerecord-5.2.2/lib/active_record/associations/collection_proxy.rb:46:in `load_target'
/usr/local/bundle/gems/activerecord-5.2.2/lib/active_record/associations/collection_proxy.rb:1032:in `records'
/usr/local/bundle/gems/activerecord-5.2.2/lib/active_record/relation/delegation.rb:71:in `each'
/usr/local/bundle/gems/globalize-5.2.0/lib/globalize/active_record/instance_methods.rb:130:in `detect'
/usr/local/bundle/gems/globalize-5.2.0/lib/globalize/active_record/instance_methods.rb:130:in `translation_for'
/usr/local/bundle/gems/globalize-5.2.0/lib/globalize/active_record/instance_methods.rb:124:in `translation'
/usr/local/bundle/gems/globalize-5.2.0/lib/globalize/active_record/instance_methods.rb:162:in `save'
/usr/local/bundle/gems/activerecord-5.2.2/lib/active_record/persistence.rb:36:in `create'
/usr/local/bundle/gems/activerecord-5.2.2/lib/active_record/relation.rb:85:in `block in create'
/usr/local/bundle/gems/activerecord-5.2.2/lib/active_record/relation.rb:281:in `scoping'
/usr/local/bundle/gems/activerecord-5.2.2/lib/active_record/relation.rb:85:in `create'
/usr/local/bundle/gems/activerecord-5.2.2/lib/active_record/relation.rb:164:in `find_or_create_by'
/usr/local/bundle/gems/activerecord-5.2.2/lib/active_record/querying.rb:8:in `find_or_create_by'
/beecom/lib/tasks/aaaaaaaa_bbbbb_cccc.rake:10:in `block (3 levels) in <top (required)>'
/beecom/lib/tasks/aaaaaaaa_bbbbb_cccc.rake:9:in `each'
/beecom/lib/tasks/aaaaaaaa_bbbbb_cccc.rake:9:in `block (2 levels) in <top (required)>'
/beecom/db/seeds.rb:209:in `<top (required)>'
/usr/local/bundle/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:285:in `load'
/usr/local/bundle/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:285:in `block in load'
/usr/local/bundle/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:257:in `load_dependency'
/usr/local/bundle/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:285:in `load'
/usr/local/bundle/gems/railties-5.2.2/lib/rails/engine.rb:551:in `load_seed'
/usr/local/bundle/gems/activerecord-5.2.2/lib/active_record/tasks/database_tasks.rb:281:in `load_seed'
/usr/local/bundle/gems/activerecord-5.2.2/lib/active_record/railties/databases.rake:194:in `block (2 levels) in <top (required)>'
/usr/local/bundle/gems/railties-5.2.2/lib/rails/commands/rake/rake_command.rb:23:in `block in perform'
/usr/local/bundle/gems/railties-5.2.2/lib/rails/commands/rake/rake_command.rb:20:in `perform'
/usr/local/bundle/gems/railties-5.2.2/lib/rails/command.rb:48:in `invoke'
/usr/local/bundle/gems/railties-5.2.2/lib/rails/commands.rb:18:in `<top (required)>'
bin/rails:4:in `require'
bin/rails:4:in `<main>'
Caused by:
OCIError: ORA-04043: object "aaaaaaaa_bbbbb_cccc_translations" does not exist
metadata.c:175:in oci8lib_260.so
/usr/local/bundle/gems/ruby-oci8-2.2.7/lib/oci8/metadata.rb:2061:in `block in describe_table'
/usr/local/bundle/gems/ruby-oci8-2.2.7/lib/oci8/metadata.rb:2060:in `times'
/usr/local/bundle/gems/ruby-oci8-2.2.7/lib/oci8/metadata.rb:2060:in `describe_table'
/usr/local/bundle/gems/activerecord-oracle_enhanced-adapter-5.2.5/lib/active_record/connection_adapters/oracle_enhanced/oci_connection.rb:350:in `describe'
/usr/local/bundle/gems/activerecord-oracle_enhanced-adapter-5.2.5/lib/active_record/connection_adapters/oracle_enhanced/oci_connection.rb:206:in `describe'
/usr/local/bundle/gems/activerecord-oracle_enhanced-adapter-5.2.5/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb:552:in `pk_and_sequence_for'
/usr/local/bundle/gems/activerecord-oracle_enhanced-adapter-5.2.5/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb:585:in `primary_key'
/usr/local/bundle/gems/activerecord-5.2.2/lib/active_record/connection_adapters/schema_cache.rb:43:in `primary_keys'
/usr/local/bundle/gems/activerecord-5.2.2/lib/active_record/attribute_methods/primary_key.rb:100:in `get_primary_key'
/usr/local/bundle/gems/activerecord-5.2.2/lib/active_record/attribute_methods/primary_key.rb:87:in `reset_primary_key'
/usr/local/bundle/gems/activerecord-5.2.2/lib/active_record/attribute_methods/primary_key.rb:75:in `primary_key'
/usr/local/bundle/gems/activerecord-5.2.2/lib/active_record/associations/foreign_association.rb:6:in `foreign_key_present?'
/usr/local/bundle/gems/activerecord-5.2.2/lib/active_record/associations/association.rb:203:in `find_target?'
/usr/local/bundle/gems/activerecord-5.2.2/lib/active_record/associations/collection_association.rb:272:in `load_target'
/usr/local/bundle/gems/activerecord-5.2.2/lib/active_record/associations/collection_proxy.rb:46:in `load_target'
/usr/local/bundle/gems/activerecord-5.2.2/lib/active_record/associations/collection_proxy.rb:1032:in `records'
/usr/local/bundle/gems/activerecord-5.2.2/lib/active_record/relation/delegation.rb:71:in `each'
/usr/local/bundle/gems/globalize-5.2.0/lib/globalize/active_record/instance_methods.rb:130:in `detect'
/usr/local/bundle/gems/globalize-5.2.0/lib/globalize/active_record/instance_methods.rb:130:in `translation_for'
/usr/local/bundle/gems/globalize-5.2.0/lib/globalize/active_record/instance_methods.rb:124:in `translation'
/usr/local/bundle/gems/globalize-5.2.0/lib/globalize/active_record/instance_methods.rb:162:in `save'
/usr/local/bundle/gems/activerecord-5.2.2/lib/active_record/persistence.rb:36:in `create'
/usr/local/bundle/gems/activerecord-5.2.2/lib/active_record/relation.rb:85:in `block in create'
/usr/local/bundle/gems/activerecord-5.2.2/lib/active_record/relation.rb:281:in `scoping'
/usr/local/bundle/gems/activerecord-5.2.2/lib/active_record/relation.rb:85:in `create'
/usr/local/bundle/gems/activerecord-5.2.2/lib/active_record/relation.rb:164:in `find_or_create_by'
/usr/local/bundle/gems/activerecord-5.2.2/lib/active_record/querying.rb:8:in `find_or_create_by'
/beecom/lib/tasks/aaaaaaaa_bbbbb_cccc.rake:10:in `block (3 levels) in <top (required)>'
/beecom/lib/tasks/aaaaaaaa_bbbbb_cccc.rake:9:in `each'
/beecom/lib/tasks/aaaaaaaa_bbbbb_cccc.rake:9:in `block (2 levels) in <top (required)>'
/beecom/db/seeds.rb:209:in `<top (required)>'
/usr/local/bundle/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:285:in `load'
/usr/local/bundle/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:285:in `block in load'
/usr/local/bundle/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:257:in `load_dependency'
/usr/local/bundle/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:285:in `load'
/usr/local/bundle/gems/railties-5.2.2/lib/rails/engine.rb:551:in `load_seed'
/usr/local/bundle/gems/activerecord-5.2.2/lib/active_record/tasks/database_tasks.rb:281:in `load_seed'
/usr/local/bundle/gems/activerecord-5.2.2/lib/active_record/railties/databases.rake:194:in `block (2 levels) in <top (required)>'
/usr/local/bundle/gems/railties-5.2.2/lib/rails/commands/rake/rake_command.rb:23:in `block in perform'
/usr/local/bundle/gems/railties-5.2.2/lib/rails/commands/rake/rake_command.rb:20:in `perform'
/usr/local/bundle/gems/railties-5.2.2/lib/rails/command.rb:48:in `invoke'
/usr/local/bundle/gems/railties-5.2.2/lib/rails/commands.rb:18:in `<top (required)>'
bin/rails:4:in `require'
bin/rails:4:in `<main>'
Tasks: TOP => db:seed
您的 table 名称 "aaaaaaaa_bbbbb_cccc_translations" 的长度为 32 字节,限制为 30,但在 12cR2 中已增加到 128。但我猜您使用的客户端工具可以访问数据库在处理较长名称时出现问题。
我正在移植 MySQL 数据库,我想迁移到 Oracle DB 12cRC2。问题是我的一些 table 的名字超过了 30 个字符。
一切正常(在弄乱了我的 schema.rb 文件之后)。
我正在使用 "Globalize" gem 来本地化我的数据库。
当我 运行 我的种子时,我的翻译出现了错误 table,比如:
OCIError: ORA-04043: object "aaaaaaaa_bbbbb_cccc_translations" does not exist
但是当我使用 sqlplus 时,我可以看到我的 table 没问题...使用 DESC 或 SELECT 查询。
我用的是oracle-instantclient12.2连接
我怀疑 table 名称长度,因为其他 table 名称较小的名称不会引发 execption
我的堆栈:
rails aborted!
ActiveRecord::ConnectionAdapters::OracleEnhanced::ConnectionException: "DESC aaaaaaaa_bbbbb_cccc_translations" failed; does it exist?
/usr/local/bundle/gems/activerecord-oracle_enhanced-adapter-5.2.5/lib/active_record/connection_adapters/oracle_enhanced/oci_connection.rb:209:in `rescue in describe'
/usr/local/bundle/gems/activerecord-oracle_enhanced-adapter-5.2.5/lib/active_record/connection_adapters/oracle_enhanced/oci_connection.rb:202:in `describe'
/usr/local/bundle/gems/activerecord-oracle_enhanced-adapter-5.2.5/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb:552:in `pk_and_sequence_for'
/usr/local/bundle/gems/activerecord-oracle_enhanced-adapter-5.2.5/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb:585:in `primary_key'
/usr/local/bundle/gems/activerecord-5.2.2/lib/active_record/connection_adapters/schema_cache.rb:43:in `primary_keys'
/usr/local/bundle/gems/activerecord-5.2.2/lib/active_record/attribute_methods/primary_key.rb:100:in `get_primary_key'
/usr/local/bundle/gems/activerecord-5.2.2/lib/active_record/attribute_methods/primary_key.rb:87:in `reset_primary_key'
/usr/local/bundle/gems/activerecord-5.2.2/lib/active_record/attribute_methods/primary_key.rb:75:in `primary_key'
/usr/local/bundle/gems/activerecord-5.2.2/lib/active_record/associations/foreign_association.rb:6:in `foreign_key_present?'
/usr/local/bundle/gems/activerecord-5.2.2/lib/active_record/associations/association.rb:203:in `find_target?'
/usr/local/bundle/gems/activerecord-5.2.2/lib/active_record/associations/collection_association.rb:272:in `load_target'
/usr/local/bundle/gems/activerecord-5.2.2/lib/active_record/associations/collection_proxy.rb:46:in `load_target'
/usr/local/bundle/gems/activerecord-5.2.2/lib/active_record/associations/collection_proxy.rb:1032:in `records'
/usr/local/bundle/gems/activerecord-5.2.2/lib/active_record/relation/delegation.rb:71:in `each'
/usr/local/bundle/gems/globalize-5.2.0/lib/globalize/active_record/instance_methods.rb:130:in `detect'
/usr/local/bundle/gems/globalize-5.2.0/lib/globalize/active_record/instance_methods.rb:130:in `translation_for'
/usr/local/bundle/gems/globalize-5.2.0/lib/globalize/active_record/instance_methods.rb:124:in `translation'
/usr/local/bundle/gems/globalize-5.2.0/lib/globalize/active_record/instance_methods.rb:162:in `save'
/usr/local/bundle/gems/activerecord-5.2.2/lib/active_record/persistence.rb:36:in `create'
/usr/local/bundle/gems/activerecord-5.2.2/lib/active_record/relation.rb:85:in `block in create'
/usr/local/bundle/gems/activerecord-5.2.2/lib/active_record/relation.rb:281:in `scoping'
/usr/local/bundle/gems/activerecord-5.2.2/lib/active_record/relation.rb:85:in `create'
/usr/local/bundle/gems/activerecord-5.2.2/lib/active_record/relation.rb:164:in `find_or_create_by'
/usr/local/bundle/gems/activerecord-5.2.2/lib/active_record/querying.rb:8:in `find_or_create_by'
/beecom/lib/tasks/aaaaaaaa_bbbbb_cccc.rake:10:in `block (3 levels) in <top (required)>'
/beecom/lib/tasks/aaaaaaaa_bbbbb_cccc.rake:9:in `each'
/beecom/lib/tasks/aaaaaaaa_bbbbb_cccc.rake:9:in `block (2 levels) in <top (required)>'
/beecom/db/seeds.rb:209:in `<top (required)>'
/usr/local/bundle/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:285:in `load'
/usr/local/bundle/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:285:in `block in load'
/usr/local/bundle/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:257:in `load_dependency'
/usr/local/bundle/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:285:in `load'
/usr/local/bundle/gems/railties-5.2.2/lib/rails/engine.rb:551:in `load_seed'
/usr/local/bundle/gems/activerecord-5.2.2/lib/active_record/tasks/database_tasks.rb:281:in `load_seed'
/usr/local/bundle/gems/activerecord-5.2.2/lib/active_record/railties/databases.rake:194:in `block (2 levels) in <top (required)>'
/usr/local/bundle/gems/railties-5.2.2/lib/rails/commands/rake/rake_command.rb:23:in `block in perform'
/usr/local/bundle/gems/railties-5.2.2/lib/rails/commands/rake/rake_command.rb:20:in `perform'
/usr/local/bundle/gems/railties-5.2.2/lib/rails/command.rb:48:in `invoke'
/usr/local/bundle/gems/railties-5.2.2/lib/rails/commands.rb:18:in `<top (required)>'
bin/rails:4:in `require'
bin/rails:4:in `<main>'
Caused by:
OCIError: ORA-04043: object "aaaaaaaa_bbbbb_cccc_translations" does not exist
metadata.c:175:in oci8lib_260.so
/usr/local/bundle/gems/ruby-oci8-2.2.7/lib/oci8/metadata.rb:2061:in `block in describe_table'
/usr/local/bundle/gems/ruby-oci8-2.2.7/lib/oci8/metadata.rb:2060:in `times'
/usr/local/bundle/gems/ruby-oci8-2.2.7/lib/oci8/metadata.rb:2060:in `describe_table'
/usr/local/bundle/gems/activerecord-oracle_enhanced-adapter-5.2.5/lib/active_record/connection_adapters/oracle_enhanced/oci_connection.rb:350:in `describe'
/usr/local/bundle/gems/activerecord-oracle_enhanced-adapter-5.2.5/lib/active_record/connection_adapters/oracle_enhanced/oci_connection.rb:206:in `describe'
/usr/local/bundle/gems/activerecord-oracle_enhanced-adapter-5.2.5/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb:552:in `pk_and_sequence_for'
/usr/local/bundle/gems/activerecord-oracle_enhanced-adapter-5.2.5/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb:585:in `primary_key'
/usr/local/bundle/gems/activerecord-5.2.2/lib/active_record/connection_adapters/schema_cache.rb:43:in `primary_keys'
/usr/local/bundle/gems/activerecord-5.2.2/lib/active_record/attribute_methods/primary_key.rb:100:in `get_primary_key'
/usr/local/bundle/gems/activerecord-5.2.2/lib/active_record/attribute_methods/primary_key.rb:87:in `reset_primary_key'
/usr/local/bundle/gems/activerecord-5.2.2/lib/active_record/attribute_methods/primary_key.rb:75:in `primary_key'
/usr/local/bundle/gems/activerecord-5.2.2/lib/active_record/associations/foreign_association.rb:6:in `foreign_key_present?'
/usr/local/bundle/gems/activerecord-5.2.2/lib/active_record/associations/association.rb:203:in `find_target?'
/usr/local/bundle/gems/activerecord-5.2.2/lib/active_record/associations/collection_association.rb:272:in `load_target'
/usr/local/bundle/gems/activerecord-5.2.2/lib/active_record/associations/collection_proxy.rb:46:in `load_target'
/usr/local/bundle/gems/activerecord-5.2.2/lib/active_record/associations/collection_proxy.rb:1032:in `records'
/usr/local/bundle/gems/activerecord-5.2.2/lib/active_record/relation/delegation.rb:71:in `each'
/usr/local/bundle/gems/globalize-5.2.0/lib/globalize/active_record/instance_methods.rb:130:in `detect'
/usr/local/bundle/gems/globalize-5.2.0/lib/globalize/active_record/instance_methods.rb:130:in `translation_for'
/usr/local/bundle/gems/globalize-5.2.0/lib/globalize/active_record/instance_methods.rb:124:in `translation'
/usr/local/bundle/gems/globalize-5.2.0/lib/globalize/active_record/instance_methods.rb:162:in `save'
/usr/local/bundle/gems/activerecord-5.2.2/lib/active_record/persistence.rb:36:in `create'
/usr/local/bundle/gems/activerecord-5.2.2/lib/active_record/relation.rb:85:in `block in create'
/usr/local/bundle/gems/activerecord-5.2.2/lib/active_record/relation.rb:281:in `scoping'
/usr/local/bundle/gems/activerecord-5.2.2/lib/active_record/relation.rb:85:in `create'
/usr/local/bundle/gems/activerecord-5.2.2/lib/active_record/relation.rb:164:in `find_or_create_by'
/usr/local/bundle/gems/activerecord-5.2.2/lib/active_record/querying.rb:8:in `find_or_create_by'
/beecom/lib/tasks/aaaaaaaa_bbbbb_cccc.rake:10:in `block (3 levels) in <top (required)>'
/beecom/lib/tasks/aaaaaaaa_bbbbb_cccc.rake:9:in `each'
/beecom/lib/tasks/aaaaaaaa_bbbbb_cccc.rake:9:in `block (2 levels) in <top (required)>'
/beecom/db/seeds.rb:209:in `<top (required)>'
/usr/local/bundle/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:285:in `load'
/usr/local/bundle/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:285:in `block in load'
/usr/local/bundle/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:257:in `load_dependency'
/usr/local/bundle/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:285:in `load'
/usr/local/bundle/gems/railties-5.2.2/lib/rails/engine.rb:551:in `load_seed'
/usr/local/bundle/gems/activerecord-5.2.2/lib/active_record/tasks/database_tasks.rb:281:in `load_seed'
/usr/local/bundle/gems/activerecord-5.2.2/lib/active_record/railties/databases.rake:194:in `block (2 levels) in <top (required)>'
/usr/local/bundle/gems/railties-5.2.2/lib/rails/commands/rake/rake_command.rb:23:in `block in perform'
/usr/local/bundle/gems/railties-5.2.2/lib/rails/commands/rake/rake_command.rb:20:in `perform'
/usr/local/bundle/gems/railties-5.2.2/lib/rails/command.rb:48:in `invoke'
/usr/local/bundle/gems/railties-5.2.2/lib/rails/commands.rb:18:in `<top (required)>'
bin/rails:4:in `require'
bin/rails:4:in `<main>'
Tasks: TOP => db:seed
您的 table 名称 "aaaaaaaa_bbbbb_cccc_translations" 的长度为 32 字节,限制为 30,但在 12cR2 中已增加到 128。但我猜您使用的客户端工具可以访问数据库在处理较长名称时出现问题。