23

I'm trying to upgrade my redmine from 1.3.0 to 2.0.0, but I have problems with the database migration. When I run the command:

rake db:migrate RAILS_ENV=production

it shows an error like

rake aborted!
uninitialized constant RAILS_ENV

My error log is:

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'

Here is the list of plugin that I am using in my old redmine:

  1. Google Apps plugin

  2. Redmine Code Review plugin

  3. Redmine Hudson plugin

halfer
  • 19,824
  • 17
  • 99
  • 186
zam
  • 269
  • 1
  • 2
  • 4

2 Answers2

75

If anyone else stumbles here there are two ways to fix the problem

  1. Don't use a column named type.
  2. Manually set the column name to something pointless:

    self.inheritance_column = :_type_disabled
    

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

cbron
  • 4,036
  • 3
  • 33
  • 40
  • 1
    It's easier just to rename it `table_type` instead of doing hacks with `inheritance_column` I tried this with nil and a symbol and the application broke on the inherited model in different areas. – Josh Bedo Jul 10 '14 at 14:57
  • This worked great (even with `nil`) in migrations for me - but I used it by defining a dummy class in the migration, which I had already been doing. I can see where making it nil in your real model might cause trouble, but it seemed to be fine on a dummy class in a migration. – stephan.com Aug 21 '19 at 18:56
  • i use `kind` instead of `type` – Dorian Nov 04 '20 at 15:54
21

The single-table inheritance error is probably caused by a column named type in your database.

If rails encounters a column name called type it assumes it's a Model that has Subclasses so the type discriminates what model to use. I guess some plugin that was not originally built for rails uses a type column in it's model and that causes Rails to fail.

Tigraine
  • 23,358
  • 11
  • 65
  • 110