{"action":"created","issue":{"url":"https://api.github.com/repos/activeadmin/activeadmin/issues/1360","labels_url":"https://api.github.com/repos/activeadmin/activeadmin/issues/1360/labels{/name}","comments_url":"https://api.github.com/repos/activeadmin/activeadmin/issues/1360/comments","events_url":"https://api.github.com/repos/activeadmin/activeadmin/issues/1360/events","html_url":"https://github.com/activeadmin/activeadmin/issues/1360","id":4768128,"number":1360,"title":"ActiveAdmin prevents migration because of one filter","user":{"login":"Screatch","id":588383,"avatar_url":"https://avatars.githubusercontent.com/u/588383?v=3","gravatar_id":"","url":"https://api.github.com/users/Screatch","html_url":"https://github.com/Screatch","followers_url":"https://api.github.com/users/Screatch/followers","following_url":"https://api.github.com/users/Screatch/following{/other_user}","gists_url":"https://api.github.com/users/Screatch/gists{/gist_id}","starred_url":"https://api.github.com/users/Screatch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Screatch/subscriptions","organizations_url":"https://api.github.com/users/Screatch/orgs","repos_url":"https://api.github.com/users/Screatch/repos","events_url":"https://api.github.com/users/Screatch/events{/privacy}","received_events_url":"https://api.github.com/users/Screatch/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2012-05-26T21:14:57Z","updated_at":"2015-07-24T15:26:59Z","closed_at":"2012-05-26T21:46:42Z","body":"It appears that this filter:\n```ruby\nfilter :user, :label => 'User', :collection => User.all.map(&:email)\n```\nPrevents migration, it just fails on the first table with this error:\n\n```sql\nMysql2::Error: Table 'adv_development.users' doesn't exist: SHOW FULL FIELDS FROM\n```\n\nI made this filter to achieve user selection in dropdown in filter and it works quite well, it's just I have to disable this filter before migration, then I can enable it again.\n\nRuby vesrion: ruby 1.9.3p0\nRails version:  Rails 3.2.2\n\nHere is the full trace of why is it failing.\n\n```text\nvitali@vitali-desktop:~/advertstar$ rake db:migrate --trace\n** Invoke db:migrate (first_time)\n** Invoke environment (first_time)\n** Execute environment\nrake aborted!\nMysql2::Error: Table 'adv_development.users' doesn't exist: SHOW FULL FIELDS FROM `users`\n/usr/lib/ruby/gems/1.9.1/gems/activerecord-3.2.2/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:243:in `query'\n/usr/lib/ruby/gems/1.9.1/gems/activerecord-3.2.2/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:243:in `block in execute'\n/usr/lib/ruby/gems/1.9.1/gems/activerecord-3.2.2/lib/active_record/connection_adapters/abstract_adapter.rb:280:in `block in log'\n/usr/lib/ruby/gems/1.9.1/gems/activesupport-3.2.2/lib/active_support/notifications/instrumenter.rb:20:in `instrument'\n/usr/lib/ruby/gems/1.9.1/gems/activerecord-3.2.2/lib/active_record/connection_adapters/abstract_adapter.rb:275:in `log'\n/usr/lib/ruby/gems/1.9.1/gems/activerecord-3.2.2/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:243:in `execute'\n/usr/lib/ruby/gems/1.9.1/gems/activerecord-3.2.2/lib/active_record/connection_adapters/mysql2_adapter.rb:211:in `execute'\n/usr/lib/ruby/gems/1.9.1/gems/activerecord-3.2.2/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:257:in `execute_and_free'\n/usr/lib/ruby/gems/1.9.1/gems/activerecord-3.2.2/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:424:in `columns'\n/usr/lib/ruby/gems/1.9.1/gems/activerecord-3.2.2/lib/active_record/connection_adapters/schema_cache.rb:12:in `block in initialize'\n/usr/lib/ruby/gems/1.9.1/gems/activerecord-3.2.2/lib/active_record/model_schema.rb:228:in `yield'\n/usr/lib/ruby/gems/1.9.1/gems/activerecord-3.2.2/lib/active_record/model_schema.rb:228:in `default'\n/usr/lib/ruby/gems/1.9.1/gems/activerecord-3.2.2/lib/active_record/model_schema.rb:228:in `columns'\n/usr/lib/ruby/gems/1.9.1/gems/activerecord-3.2.2/lib/active_record/model_schema.rb:237:in `columns_hash'\n/usr/lib/ruby/gems/1.9.1/gems/activerecord-3.2.2/lib/active_record/locking/optimistic.rb:129:in `locking_enabled?'\n/usr/lib/ruby/gems/1.9.1/gems/activerecord-3.2.2/lib/active_record/relation.rb:170:in `exec_queries'\n/usr/lib/ruby/gems/1.9.1/gems/activerecord-3.2.2/lib/active_record/relation.rb:160:in `block in to_a'\n/usr/lib/ruby/gems/1.9.1/gems/activerecord-3.2.2/lib/active_record/explain.rb:33:in `logging_query_plan'\n/usr/lib/ruby/gems/1.9.1/gems/activerecord-3.2.2/lib/active_record/relation.rb:159:in `to_a'\n/usr/lib/ruby/gems/1.9.1/gems/activerecord-3.2.2/lib/active_record/relation/delegation.rb:6:in `map'\n/home/vitali/advertstar/app/admin/webmaster_sites.rb:6:in `block in <top (required)>'\n/usr/lib/ruby/gems/1.9.1/gems/activeadmin-0.4.4/lib/active_admin/dsl.rb:13:in `instance_eval'\n/usr/lib/ruby/gems/1.9.1/gems/activeadmin-0.4.4/lib/active_admin/dsl.rb:13:in `run_registration_block'\n/usr/lib/ruby/gems/1.9.1/gems/activeadmin-0.4.4/lib/active_admin/namespace.rb:178:in `parse_registration_block'\n/usr/lib/ruby/gems/1.9.1/gems/activeadmin-0.4.4/lib/active_admin/namespace.rb:54:in `register'\n/usr/lib/ruby/gems/1.9.1/gems/activeadmin-0.4.4/lib/active_admin/application.rb:99:in `register'\n/usr/lib/ruby/gems/1.9.1/gems/activeadmin-0.4.4/lib/active_admin.rb:74:in `register'\n/home/vitali/advertstar/app/admin/webmaster_sites.rb:2:in `<top (required)>'\n/usr/lib/ruby/gems/1.9.1/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:245:in `load'\n/usr/lib/ruby/gems/1.9.1/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:245:in `block in load'\n/usr/lib/ruby/gems/1.9.1/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:236:in `load_dependency'\n/usr/lib/ruby/gems/1.9.1/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:245:in `load'\n/usr/lib/ruby/gems/1.9.1/gems/activeadmin-0.4.4/lib/active_admin/application.rb:161:in `block in load!'\n/usr/lib/ruby/gems/1.9.1/gems/activeadmin-0.4.4/lib/active_admin/application.rb:161:in `each'\n/usr/lib/ruby/gems/1.9.1/gems/activeadmin-0.4.4/lib/active_admin/application.rb:161:in `load!'\n/usr/lib/ruby/gems/1.9.1/gems/activeadmin-0.4.4/lib/active_admin/application.rb:187:in `routes'\n/usr/lib/ruby/gems/1.9.1/gems/activeadmin-0.4.4/lib/active_admin.rb:78:in `routes'\n/home/vitali/advertstar/config/routes.rb:3:in `block in <top (required)>'\n/usr/lib/ruby/gems/1.9.1/gems/actionpack-3.2.2/lib/action_dispatch/routing/route_set.rb:276:in `instance_exec'\n/usr/lib/ruby/gems/1.9.1/gems/actionpack-3.2.2/lib/action_dispatch/routing/route_set.rb:276:in `eval_block'\n/usr/lib/ruby/gems/1.9.1/gems/actionpack-3.2.2/lib/action_dispatch/routing/route_set.rb:254:in `draw'\n/home/vitali/advertstar/config/routes.rb:1:in `<top (required)>'\n/usr/lib/ruby/gems/1.9.1/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:245:in `load'\n/usr/lib/ruby/gems/1.9.1/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:245:in `block in load'\n/usr/lib/ruby/gems/1.9.1/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:236:in `load_dependency'\n/usr/lib/ruby/gems/1.9.1/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:245:in `load'\n/usr/lib/ruby/gems/1.9.1/gems/railties-3.2.2/lib/rails/application/routes_reloader.rb:40:in `block in load_paths'\n/usr/lib/ruby/gems/1.9.1/gems/railties-3.2.2/lib/rails/application/routes_reloader.rb:40:in `each'\n/usr/lib/ruby/gems/1.9.1/gems/railties-3.2.2/lib/rails/application/routes_reloader.rb:40:in `load_paths'\n/usr/lib/ruby/gems/1.9.1/gems/railties-3.2.2/lib/rails/application/routes_reloader.rb:16:in `reload!'\n/usr/lib/ruby/gems/1.9.1/gems/railties-3.2.2/lib/rails/application.rb:108:in `reload_routes!'\n/usr/lib/ruby/gems/1.9.1/gems/activeadmin-0.4.4/lib/active_admin/reloader.rb:34:in `reload!'\n/usr/lib/ruby/gems/1.9.1/gems/activeadmin-0.4.4/lib/active_admin/reloader.rb:61:in `block in attach!'\n/usr/lib/ruby/gems/1.9.1/gems/activesupport-3.2.2/lib/active_support/callbacks.rb:429:in `_run__2003460589266378899__prepare__2730696565760933600__callbacks'\n/usr/lib/ruby/gems/1.9.1/gems/activesupport-3.2.2/lib/active_support/callbacks.rb:405:in `__run_callback'\n/usr/lib/ruby/gems/1.9.1/gems/activesupport-3.2.2/lib/active_support/callbacks.rb:385:in `_run_prepare_callbacks'\n/usr/lib/ruby/gems/1.9.1/gems/activesupport-3.2.2/lib/active_support/callbacks.rb:81:in `run_callbacks'\n/usr/lib/ruby/gems/1.9.1/gems/actionpack-3.2.2/lib/action_dispatch/middleware/reloader.rb:74:in `prepare!'\n/usr/lib/ruby/gems/1.9.1/gems/actionpack-3.2.2/lib/action_dispatch/middleware/reloader.rb:48:in `prepare!'\n/usr/lib/ruby/gems/1.9.1/gems/railties-3.2.2/lib/rails/application/finisher.rb:47:in `block in <module:Finisher>'\n/usr/lib/ruby/gems/1.9.1/gems/railties-3.2.2/lib/rails/initializable.rb:30:in `instance_exec'\n/usr/lib/ruby/gems/1.9.1/gems/railties-3.2.2/lib/rails/initializable.rb:30:in `run'\n/usr/lib/ruby/gems/1.9.1/gems/railties-3.2.2/lib/rails/initializable.rb:55:in `block in run_initializers'\n/usr/lib/ruby/gems/1.9.1/gems/railties-3.2.2/lib/rails/initializable.rb:54:in `each'\n/usr/lib/ruby/gems/1.9.1/gems/railties-3.2.2/lib/rails/initializable.rb:54:in `run_initializers'\n/usr/lib/ruby/gems/1.9.1/gems/railties-3.2.2/lib/rails/application.rb:136:in `initialize!'\n/usr/lib/ruby/gems/1.9.1/gems/railties-3.2.2/lib/rails/railtie/configurable.rb:30:in `method_missing'\n/home/vitali/advertstar/config/environment.rb:5:in `<top (required)>'\n/usr/lib/ruby/gems/1.9.1/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:251:in `require'\n/usr/lib/ruby/gems/1.9.1/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:251:in `block in require'\n/usr/lib/ruby/gems/1.9.1/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:236:in `load_dependency'\n/usr/lib/ruby/gems/1.9.1/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:251:in `require'\n/usr/lib/ruby/gems/1.9.1/gems/railties-3.2.2/lib/rails/application.rb:103:in `require_environment!'\n/usr/lib/ruby/gems/1.9.1/gems/railties-3.2.2/lib/rails/application.rb:292:in `block (2 levels) in initialize_tasks'\n/usr/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `call'\n/usr/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `block in execute'\n/usr/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `each'\n/usr/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `execute'\n/usr/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain'\n/usr/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'\n/usr/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'\n/usr/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:176:in `block in invoke_prerequisites'\n/usr/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:174:in `each'\n/usr/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:174:in `invoke_prerequisites'\n/usr/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:157:in `block in invoke_with_call_chain'\n/usr/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'\n/usr/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'\n/usr/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:144:in `invoke'\n/usr/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:116:in `invoke_task'\n/usr/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block (2 levels) in top_level'\n/usr/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `each'\n/usr/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block in top_level'\n/usr/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'\n/usr/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:88:in `top_level'\n/usr/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:66:in `block in run'\n/usr/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'\n/usr/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run'\n/usr/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/bin/rake:33:in `<top (required)>'\n/usr/bin/rake:19:in `load'\n/usr/bin/rake:19:in `<main>'\nTasks: TOP => db:migrate => environment\n```\n\nAny help regarding this issue is highly appreciated."},"comment":{"url":"https://api.github.com/repos/activeadmin/activeadmin/issues/comments/124558647","html_url":"https://github.com/activeadmin/activeadmin/issues/1360#issuecomment-124558647","issue_url":"https://api.github.com/repos/activeadmin/activeadmin/issues/1360","id":124558647,"user":{"login":"alexander-lazarov","id":5956709,"avatar_url":"https://avatars.githubusercontent.com/u/5956709?v=3","gravatar_id":"","url":"https://api.github.com/users/alexander-lazarov","html_url":"https://github.com/alexander-lazarov","followers_url":"https://api.github.com/users/alexander-lazarov/followers","following_url":"https://api.github.com/users/alexander-lazarov/following{/other_user}","gists_url":"https://api.github.com/users/alexander-lazarov/gists{/gist_id}","starred_url":"https://api.github.com/users/alexander-lazarov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alexander-lazarov/subscriptions","organizations_url":"https://api.github.com/users/alexander-lazarov/orgs","repos_url":"https://api.github.com/users/alexander-lazarov/repos","events_url":"https://api.github.com/users/alexander-lazarov/events{/privacy}","received_events_url":"https://api.github.com/users/alexander-lazarov/received_events","type":"User","site_admin":false},"created_at":"2015-07-24T15:26:59Z","updated_at":"2015-07-24T15:26:59Z","body":"I had a similar problem, but I couldn't figure out how to fix it by wrapping the problem code with a proc,. That's why I used an ugly fix - begin/rescue construction to suppress the exception from bubbling up and halting the database migration. Not the best code in the world, but couldn't fix it better. Hope it helps someone.\r\n\r\n```ruby\r\nActiveAdmin.register Entry do\r\n  belongs_to :event\r\n  navigation_menu :event\r\n\r\n  scope :all, default: true\r\n\r\n  # The code in the rescue block is executed during DB migrations\r\n  # this raises an exception because event_class table might not be created\r\n  # yet so this is an (ugly) workaround to make db:migrate task work.\r\n  # For more info see https://github.com/activeadmin/activeadmin/issues/1360\r\n  begin\r\n    EventClass.all.each do |event_class|\r\n      curr = proc { event_class.event.id == @event.id }\r\n      scope event_class.name + ' - ' + event_class.event.name,\r\n            if: curr do |scope|\r\n        scope.where(event_class_id: event_class.id)\r\n      end\r\n    end\r\n  rescue ActiveRecord::StatementInvalid\r\n  end\r\nend\r\n```\r\n"}}