【问题标题】:ActiveRecord::SubclassNotFoundActiveRecord::SubclassNotFound
【发布时间】:2012-07-13 11:55:04
【问题描述】:

我正在尝试将我的 redmine 从 1.3.0 升级到 2.0.0,但我遇到了数据库迁移问题。当我运行命令时:

rake db:migrate RAILS_ENV=production

它显示类似的错误

rake aborted!
uninitialized constant RAILS_ENV

我的错误日志是:

ActiveRecord::SubclassNotFound (The single-table inheritance mechanism failed to locate the subclass: 'GoogleAppsAuthSource'. This error is raised because the column 'type' is reserved for storing the class in case of inheritance. Please rename this column if you didn't intend it to be used for storing the inheritance class or overwrite AuthSource.inheritance_column to use another column for that information.):
app/models/user.rb:139:in `try_to_login'
app/controllers/account_controller.rb:143:in `password_authentication'
app/controllers/account_controller.rb:138:in `authenticate_user'
app/controllers/account_controller.rb:30:in `login'

这是我在旧 redmine 中使用的插件列表:

  1. Google Apps 插件

  2. Redmine 代码审查插件

  3. Redmine Hudson 插件

【问题讨论】:

    标签: ruby-on-rails ruby redmine


    【解决方案1】:

    如果其他人在这里绊倒了,有两种方法可以解决问题

    1. 不要使用名为 type 的列。
    2. 手动将列名设置为无意义的:

      self.inheritance_column = :_type_disabled
      

      见:http://apidock.com/rails/ActiveRecord/Base/inheritance_column/class

    【讨论】:

    • 将其重命名为 table_type 而不是使用 inheritance_column 进行黑客攻击更容易我用 nil 和一个符号尝试了这个,应用程序在不同区域的继承模型上崩溃了。
    • 这对我来说在迁移中效果很好(即使使用nil) - 但我通过在迁移中定义一个虚拟类来使用它,我已经在这样做了。我可以看到在您的真实模型中将其设为 nil 可能会导致麻烦,但在迁移中的虚拟类上似乎没问题。
    • 我使用kind 而不是type
    【解决方案2】:

    单表继承错误很可能是你的数据库中有一个名为type的列引起的。

    如果 rails 遇到名为 type 的列名,它会假定它是具有子类的模型,因此类型会区分要使用的模型。我猜一些最初不是为 rails 构建的插件在其模型中使用了 type 列,这会导致 Rails 失败。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-01-13
      • 1970-01-01
      • 1970-01-01
      • 2012-04-05
      • 1970-01-01
      • 2017-04-14
      • 2015-06-23
      • 1970-01-01
      相关资源
      最近更新 更多