Bug #4518
openDB migrations: Can't DROP 'role_id'; check that column/key exists
Added by Dominic Cleal over 10 years ago. Updated over 10 years ago.
Description
Between 1.3 to 1.4, the following error occurs:
$ /usr/sbin/foreman-rake db:migrate == RemoveUnusedRoleFields: migrating ========================================= -- remove_column(:users, :role_id) rake aborted! An error has occurred, all later migrations canceled: Mysql2::Error: Can't DROP 'role_id'; check that column/key exists: ALTER TABLE `users` DROP `role_id` Tasks: TOP => db:migrate (See full trace by running task with --trace)
It might also be the second column removal in the migration causing it on the first run.
Workaround: comment out lines 3 and 4 in /usr/share/foreman/db/migrate/20130924145800_remove_unused_role_fields.rb, run foreman-rake db:migrate; foreman-rake db:seed
and restart Apache/Foreman.
Updated by Dominic Cleal over 10 years ago
- Has duplicate Bug #4523: DB migration fails while upgrading theforeman from 1.3 to 1.4 added
Updated by Dominic Cleal over 10 years ago
A user just reported this error on a migration up from 0.4 to 1.4 in steps on their first migration run:
PG::UndefinedColumn: ERROR: column "inherited_from" of relation "user_roles" does not exist
I can't find any indication in git history though that this might have been added later.
Updated by Brian Galura over 10 years ago
I am also having this going from 1.3.2 to 1.4.1
- foreman-rake db:migrate
RemoveUnusedRoleFields: migrating =======================================
-- remove_column(:users, :role_id)
> 0.0098sremove_column(:user_roles, :inherited_from)
-
rake aborted!
An error has occurred, all later migrations canceled:
Mysql2::Error: Can't DROP 'inherited_from'; check that column/key exists: ALTER TABLE `user_roles` DROP `inherited_from`
Tasks: TOP => db:migrate(See full trace by running task with --trace)
[root@foreman ~]# foreman-rake db:migrate --trace
- Invoke db:migrate (first_time)
- Invoke environment (first_time)
- Execute environment
- Invoke db:load_config (first_time)
- Execute db:load_config
- Execute db:migrate
RemoveUnusedRoleFields: migrating =======================================
-- remove_column(:users, :role_id)
rake aborted!
An error has occurred, all later migrations canceled:
Mysql2::Error: Can't DROP 'role_id'; check that column/key exists: ALTER TABLE `users` DROP `role_id`
/opt/rh/ruby193/root/usr/share/gems/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:245:in `query'
/opt/rh/ruby193/root/usr/share/gems/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:245:in `block in execute'
/opt/rh/ruby193/root/usr/share/gems/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract_adapter.rb:280:in `block in log'
/opt/rh/ruby193/root/usr/share/gems/gems/activesupport-3.2.8/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/opt/rh/ruby193/root/usr/share/gems/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract_adapter.rb:275:in `log'
/opt/rh/ruby193/root/usr/share/gems/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:245:in `execute'
/opt/rh/ruby193/root/usr/share/gems/gems/activerecord-3.2.8/lib/active_record/connection_adapters/mysql2_adapter.rb:211:in `execute'
/opt/rh/ruby193/root/usr/share/gems/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract/schema_statements.rb:279:in `block in remove_column
'
/opt/rh/ruby193/root/usr/share/gems/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract/schema_statements.rb:278:in `each'
/opt/rh/ruby193/root/usr/share/gems/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract/schema_statements.rb:278:in `remove_column'
/opt/rh/ruby193/root/usr/share/gems/gems/activerecord-3.2.8/lib/active_record/migration.rb:466:in `block in method_missing'
/opt/rh/ruby193/root/usr/share/gems/gems/activerecord-3.2.8/lib/active_record/migration.rb:438:in `block in say_with_time'
/opt/rh/ruby193/root/usr/share/ruby/benchmark.rb:280:in `measure'
/opt/rh/ruby193/root/usr/share/gems/gems/activerecord-3.2.8/lib/active_record/migration.rb:438:in `say_with_time'
/opt/rh/ruby193/root/usr/share/gems/gems/activerecord-3.2.8/lib/active_record/migration.rb:458:in `method_missing'
/usr/share/foreman/db/migrate/20130924145800_remove_unused_role_fields.rb:3:in `up'
/opt/rh/ruby193/root/usr/share/gems/gems/activerecord-3.2.8/lib/active_record/migration.rb:410:in `block (2 levels) in migrate'
/opt/rh/ruby193/root/usr/share/ruby/benchmark.rb:280:in `measure'
/opt/rh/ruby193/root/usr/share/gems/gems/activerecord-3.2.8/lib/active_record/migration.rb:410:in `block in migrate'
/opt/rh/ruby193/root/usr/share/gems/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:123:in `with_connection'
/opt/rh/ruby193/root/usr/share/gems/gems/activerecord-3.2.8/lib/active_record/migration.rb:389:in `migrate'
/opt/rh/ruby193/root/usr/share/gems/gems/activerecord-3.2.8/lib/active_record/migration.rb:528:in `migrate'
/opt/rh/ruby193/root/usr/share/gems/gems/activerecord-3.2.8/lib/active_record/migration.rb:720:in `block (2 levels) in migrate'
/opt/rh/ruby193/root/usr/share/gems/gems/activerecord-3.2.8/lib/active_record/migration.rb:777:in `call'
/opt/rh/ruby193/root/usr/share/gems/gems/activerecord-3.2.8/lib/active_record/migration.rb:777:in `ddl_transaction'
/opt/rh/ruby193/root/usr/share/gems/gems/activerecord-3.2.8/lib/active_record/migration.rb:719:in `block in migrate'
/opt/rh/ruby193/root/usr/share/gems/gems/activerecord-3.2.8/lib/active_record/migration.rb:700:in `each'
/opt/rh/ruby193/root/usr/share/gems/gems/activerecord-3.2.8/lib/active_record/migration.rb:700:in `migrate'
/opt/rh/ruby193/root/usr/share/gems/gems/activerecord-3.2.8/lib/active_record/migration.rb:570:in `up'
/opt/rh/ruby193/root/usr/share/gems/gems/activerecord-3.2.8/lib/active_record/migration.rb:551:in `migrate'
/opt/rh/ruby193/root/usr/share/gems/gems/activerecord-3.2.8/lib/active_record/railties/databases.rake:153:in `block (2 levels) in <top (required)>'
/opt/rh/ruby193/root/usr/share/ruby/rake/task.rb:205:in `call'
/opt/rh/ruby193/root/usr/share/ruby/rake/task.rb:205:in `block in execute'
/opt/rh/ruby193/root/usr/share/ruby/rake/task.rb:200:in `each'
/opt/rh/ruby193/root/usr/share/ruby/rake/task.rb:200:in `execute'
/opt/rh/ruby193/root/usr/share/ruby/rake/task.rb:158:in `block in invoke_with_call_chain'
/opt/rh/ruby193/root/usr/share/ruby/monitor.rb:211:in `mon_synchronize'
/opt/rh/ruby193/root/usr/share/ruby/rake/task.rb:151:in `invoke_with_call_chain'
/opt/rh/ruby193/root/usr/share/ruby/rake/task.rb:144:in `invoke'
/opt/rh/ruby193/root/usr/share/ruby/rake/application.rb:116:in `invoke_task'
/opt/rh/ruby193/root/usr/share/ruby/rake/application.rb:94:in `block (2 levels) in top_level'
/opt/rh/ruby193/root/usr/share/ruby/rake/application.rb:94:in `each'
/opt/rh/ruby193/root/usr/share/ruby/rake/application.rb:94:in `block in top_level'
/opt/rh/ruby193/root/usr/share/ruby/rake/application.rb:133:in `standard_exception_handling'
/opt/rh/ruby193/root/usr/share/ruby/rake/application.rb:88:in `top_level'
/opt/rh/ruby193/root/usr/share/ruby/rake/application.rb:66:in `block in run'
/opt/rh/ruby193/root/usr/share/ruby/rake/application.rb:133:in `standard_exception_handling'
/opt/rh/ruby193/root/usr/share/ruby/rake/application.rb:63:in `run'
/opt/rh/ruby193/root/usr/bin/rake:32:in `<main>'
Tasks: TOP => db:migrate
Updated by Joshua Hoblitt over 10 years ago
This happens when migrating from 1.2 -> 1.5 directly and between 1.3 -> 1.4. The fix is to comment out the remove_column methods in 20130924145800_remove_unused_role_fields.rb
== RemoveUnusedRoleFields: migrating ========================================= -- remove_column(:users, :role_id) -> 0.0227s -- remove_column(:user_roles, :inherited_from) rake aborted! An error has occurred, all later migrations canceled: Mysql2::Error: Can't DROP 'inherited_from'; check that column/key exists: ALTER TABLE `user_roles` DROP `inherited_from` Tasks: TOP => db:migrate (See full trace by running task with --trace) 20130924145800_remove_unused_role_fields.rb class RemoveUnusedRoleFields < ActiveRecord::Migration def up remove_column :users, :role_id #remove_column :user_roles, :inherited_from end def down add_column :users, :role_id, :integer add_column :user_roles, :inherited_from, :integer end end == RemoveUnusedRoleFields: migrating ========================================= -- remove_column(:users, :role_id) rake aborted! An error has occurred, all later migrations canceled: Mysql2::Error: Can't DROP 'role_id'; check that column/key exists: ALTER TABLE `users` DROP `role_id` Tasks: TOP => db:migrate (See full trace by running task with --trace) 20130924145800_remove_unused_role_fields.rb class RemoveUnusedRoleFields < ActiveRecord::Migration def up #remove_column :users, :role_id #remove_column :user_roles, :inherited_from end def down add_column :users, :role_id, :integer add_column :user_roles, :inherited_from, :integer end end