ruby-on-rails - Rails 使用复数表名,即使我告诉它使用单数

标签 ruby-on-rails database

我尝试运行 rake test:profile,但出现了这个错误:

... Table 'mcif2.accounts' doesn't exist: DELETE FROM `accounts`

我知道 accounts 不存在。它称为帐户

我知道 Rails 默认使用复数表名,但这是我的 config/environment.rb 的样子:

# Load the rails application
require File.expand_path('../application', __FILE__)

# Initialize the rails application
McifRails::Application.initialize!

ActiveRecord::Base.pluralize_table_names = false

下面是 db/schema.rb 的样子:

ActiveRecord::Schema.define(:version => 0) do

  create_table "account", :force => true do |t|
    t.integer   "customer_id",              :limit => 8,                                         :null => false
    t.string    "account_number",                                                                :null => false
    t.integer   "account_type_id",          :limit => 8
    t.date      "open_date",                                                                     :null => false

所以我不明白为什么 Rails 有时仍要将其称为 accounts。有什么想法吗?

如果它有助于提供任何线索,heregrep -ir 'accounts' * 的结果。

最佳答案

我的猜测是您已将夹具命名为 accounts.yml 或在其中一项性能测试中使用了指令 fixtures :accounts。 Rails 在不知道模型的情况下使用夹具名称填充相关表。

关于ruby-on-rails - Rails 使用复数表名,即使我告诉它使用单数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4693192/

相关文章:

mysql - 将 MySQL 转储导入特定表空间

mysql - 这些索引之间的 SELECT 查询速度差异 : *UNIQUE(col1, col2)* 与 *FK(col1)、FK(col2)*

mysql - rails 3 关系模型的脚手架

ruby-on-rails - Rails ActiveStorage 版本控制(使用 paper_trail 或类似的东西)

javascript - Rails 应用程序中的 JQuery 插件 lightbox_me

database - PostgreSQL 9 : could not fsync file "base/16386": Invalid argument

javascript - MongoDB 使用脚本更新数据

sql - 在 postgresql 中, "database"和 "relation"有什么区别? ('error relation x does not exist' , 'error database x already exists' )

ruby-on-rails - 如何找出日志消息的来源(并禁用它)?

mysql - 我将如何设计这个 MySQL 模式?