I was in the middle of my coding when an error arises while I was calling a sub-class. To be exact, the following error was produced:

The single-table inheritance mechanism failed to locate the subclass: '1'. 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 [InsertClassNameHere].inheritance_column to use another column for that information.

The single-table inheritance mechanism failed to locate the subclass: '1'

My Case...

I was trying to call the sub-class of one of my classes. (e.g. Group is the class name and Member is the sub-class of the group.)

Upon calling @group.members, the error mentioned above arises.

Analysis of the Error Message

Based on the error message, it seems that the column name type is one of the reserved keywords used in 'storing the class in case of inheritance'.

From experience, it seems that this is the same as using the word lock as column name which is also a reserved keyword.

Solution to the Error

To resolve this issue, I simply rename my column to something that I think is not reserved.

You may want to access SQL to manually rename it. Just make sure to update the changes too within the db folder of your rails application.

Another way is to rollback the migration, update the migration file, then migrate it again.

$ rake db:rollback
...
$ rake db:migrate

The last approach is applicable if the last table was the one causing the error and the said table is empty. This is because, rollback will completely drop your table from your database.


No comments :

Post a Comment