Migrations Fail for New Models #292

Closed
clintonb opened this Issue Jul 12, 2011 · 28 comments

Projects

None yet
@clintonb

I created a new model and corresponding admin controller. When I attempt to run a migration, it fails due to the model's table not existing. I have traced this problem to a callback, to_prepare, that is reloading routes during the migration.

For now I have added a condition on the call to ActiveAdmin.routes() call:

ActiveAdmin.routes(self) if $ARGV.find_all { |x| x =~ /migrate|rollback/i}.empty?

Here is a stack trace from the migration:

exoadmin@build-linux:/var/lib/jenkins/jobs/Rails/workspace$ rake RAILS_ENV=test db:migrate --trace
(in /var/lib/jenkins/jobs/Rails/workspace)
/usr/lib/ruby/gems/1.9.1/gems/tlsmail-0.0.1/lib/net/smtp.rb:806: warning: already initialized constant SMTPSession
/usr/lib/ruby/gems/1.9.1/gems/tlsmail-0.0.1/lib/net/pop.rb:687: warning: already initialized constant POP
/usr/lib/ruby/gems/1.9.1/gems/tlsmail-0.0.1/lib/net/pop.rb:688: warning: already initialized constant POPSession
/usr/lib/ruby/gems/1.9.1/gems/tlsmail-0.0.1/lib/net/pop.rb:689: warning: already initialized constant POP3Session
/usr/lib/ruby/gems/1.9.1/gems/tlsmail-0.0.1/lib/net/pop.rb:702: warning: already initialized constant APOPSession
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
rake aborted!
Table 'office_ready_test.resellers' doesn't exist
/usr/lib/ruby/gems/1.9.1/gems/mysql2-0.2.11/lib/active_record/connection_adapters/mysql2_adapter.rb:263:in query' /usr/lib/ruby/gems/1.9.1/gems/mysql2-0.2.11/lib/active_record/connection_adapters/mysql2_adapter.rb:263:inexecute'
/usr/lib/ruby/gems/1.9.1/gems/mysql2-0.2.11/lib/active_record/connection_adapters/mysql2_adapter.rb:413:in columns' /usr/lib/ruby/gems/1.9.1/gems/activerecord-3.0.7/lib/active_record/base.rb:680:incolumns'
/usr/lib/ruby/gems/1.9.1/gems/activerecord-3.0.7/lib/active_record/base.rb:693:in column_names' /usr/lib/ruby/gems/1.9.1/gems/activerecord-3.0.7/lib/active_record/base.rb:706:incolumn_methods_hash'
/usr/lib/ruby/gems/1.9.1/gems/activerecord-3.0.7/lib/active_record/base.rb:1036:in block in all_attributes_exists?' /usr/lib/ruby/gems/1.9.1/gems/activerecord-3.0.7/lib/active_record/base.rb:1035:ineach'
/usr/lib/ruby/gems/1.9.1/gems/activerecord-3.0.7/lib/active_record/base.rb:1035:in all?' /usr/lib/ruby/gems/1.9.1/gems/activerecord-3.0.7/lib/active_record/base.rb:1035:inall_attributes_exists?'
/usr/lib/ruby/gems/1.9.1/gems/activerecord-3.0.7/lib/active_record/base.rb:984:in method_missing' /var/lib/jenkins/jobs/Rails/workspace/app/models/reseller.rb:13:inclass:Reseller'
/var/lib/jenkins/jobs/Rails/workspace/app/models/reseller.rb:1:in <top (required)>' /usr/lib/ruby/gems/1.9.1/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:239:inrequire'
/usr/lib/ruby/gems/1.9.1/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:239:in block in require' /usr/lib/ruby/gems/1.9.1/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:227:inload_dependency'
/usr/lib/ruby/gems/1.9.1/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:239:in require' /usr/lib/ruby/gems/1.9.1/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:346:inrequire_or_load'
/usr/lib/ruby/gems/1.9.1/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:491:in load_missing_constant' /usr/lib/ruby/gems/1.9.1/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:183:inblock in const_missing'
/usr/lib/ruby/gems/1.9.1/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:181:in each' /usr/lib/ruby/gems/1.9.1/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:181:inconst_missing'
/var/lib/jenkins/jobs/Rails/workspace/app/admin/resellers.rb:14:in <top (required)>' /usr/lib/ruby/gems/1.9.1/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:235:inload'
/usr/lib/ruby/gems/1.9.1/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:235:in block in load' /usr/lib/ruby/gems/1.9.1/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:227:inload_dependency'
/usr/lib/ruby/gems/1.9.1/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:235:in load' /usr/lib/ruby/gems/1.9.1/gems/activeadmin-0.2.2/lib/active_admin.rb:185:inblock in load!'
/usr/lib/ruby/gems/1.9.1/gems/activeadmin-0.2.2/lib/active_admin.rb:185:in each' /usr/lib/ruby/gems/1.9.1/gems/activeadmin-0.2.2/lib/active_admin.rb:185:inload!'
/usr/lib/ruby/gems/1.9.1/gems/activeadmin-0.2.2/lib/active_admin.rb:212:in routes' /var/lib/jenkins/jobs/Rails/workspace/config/routes.rb:3:inblock in <top (required)>'
/usr/lib/ruby/gems/1.9.1/gems/actionpack-3.0.7/lib/action_dispatch/routing/route_set.rb:233:in instance_exec' /usr/lib/ruby/gems/1.9.1/gems/actionpack-3.0.7/lib/action_dispatch/routing/route_set.rb:233:indraw'
/var/lib/jenkins/jobs/Rails/workspace/config/routes.rb:1:in <top (required)>' /usr/lib/ruby/gems/1.9.1/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:235:inload'
/usr/lib/ruby/gems/1.9.1/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:235:in block in load' /usr/lib/ruby/gems/1.9.1/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:227:inload_dependency'
/usr/lib/ruby/gems/1.9.1/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:235:in load' /usr/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/application.rb:127:inblock in reload_routes!'
/usr/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/application.rb:127:in each' /usr/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/application.rb:127:inreload_routes!'
/usr/lib/ruby/gems/1.9.1/gems/activeadmin-0.2.2/lib/active_admin.rb:123:in block in setup' /usr/lib/ruby/gems/1.9.1/gems/activesupport-3.0.7/lib/active_support/callbacks.rb:420:in_run_prepare_callbacks'
/usr/lib/ruby/gems/1.9.1/gems/actionpack-3.0.7/lib/action_dispatch/middleware/callbacks.rb:40:in initialize' /usr/lib/ruby/gems/1.9.1/gems/actionpack-3.0.7/lib/action_dispatch/middleware/stack.rb:33:innew'
/usr/lib/ruby/gems/1.9.1/gems/actionpack-3.0.7/lib/action_dispatch/middleware/stack.rb:33:in build' /usr/lib/ruby/gems/1.9.1/gems/actionpack-3.0.7/lib/action_dispatch/middleware/stack.rb:79:inblock in build'
/usr/lib/ruby/gems/1.9.1/gems/actionpack-3.0.7/lib/action_dispatch/middleware/stack.rb:79:in each' /usr/lib/ruby/gems/1.9.1/gems/actionpack-3.0.7/lib/action_dispatch/middleware/stack.rb:79:ininject'
/usr/lib/ruby/gems/1.9.1/gems/actionpack-3.0.7/lib/action_dispatch/middleware/stack.rb:79:in build' /usr/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/application.rb:162:inapp'
/usr/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/application/finisher.rb:35:in block in <module:Finisher>' /usr/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/initializable.rb:25:ininstance_exec'
/usr/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/initializable.rb:25:in run' /usr/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/initializable.rb:50:inblock in run_initializers'
/usr/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/initializable.rb:49:in each' /usr/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/initializable.rb:49:inrun_initializers'
/usr/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/application.rb:134:in initialize!' /usr/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/application.rb:77:inmethod_missing'
/var/lib/jenkins/jobs/Rails/workspace/config/environment.rb:5:in <top (required)>' /usr/lib/ruby/gems/1.9.1/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:239:inrequire'
/usr/lib/ruby/gems/1.9.1/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:239:in block in require' /usr/lib/ruby/gems/1.9.1/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:225:inblock in load_dependency'
/usr/lib/ruby/gems/1.9.1/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:596:in new_constants_in' /usr/lib/ruby/gems/1.9.1/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:225:inload_dependency'
/usr/lib/ruby/gems/1.9.1/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:239:in require' /usr/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/application.rb:103:inrequire_environment!'
/usr/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/application.rb:217:in block in initialize_tasks' /usr/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:636:incall'
/usr/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:636:in block in execute' /usr/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:631:ineach'
/usr/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:631:in execute' /usr/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:597:inblock in invoke_with_call_chain'
/usr/lib/ruby/1.9.1/monitor.rb:201:in mon_synchronize' /usr/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:590:ininvoke_with_call_chain'
/usr/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:607:in block in invoke_prerequisites' /usr/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:604:ineach'
/usr/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:604:in invoke_prerequisites' /usr/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:596:inblock in invoke_with_call_chain'
/usr/lib/ruby/1.9.1/monitor.rb:201:in mon_synchronize' /usr/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:590:ininvoke_with_call_chain'
/usr/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:583:in invoke' /usr/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:2051:ininvoke_task'
/usr/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:2029:in block (2 levels) in top_level' /usr/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:2029:ineach'
/usr/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:2029:in block in top_level' /usr/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:2068:instandard_exception_handling'
/usr/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:2023:in top_level' /usr/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:2001:inblock in run'
/usr/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:2068:in standard_exception_handling' /usr/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:1998:inrun'
/usr/lib/ruby/gems/1.9.1/gems/rake-0.8.7/bin/rake:31:in <top (required)>' /usr/bin/rake:19:inload'
/usr/bin/rake:19:in `

'

@qnm
qnm commented Sep 12, 2011

I have the same problem bootstrapping an app with an empty DB - I can't run migrations because the tables that routes references do not exist.

@clintonb Thanks for the above workaround.

@macfanatic
Contributor

Currently, if I have to setup an application on a production server after being built on a dev machine (using ActiveAdmin of course), I check out the project from the repo and just rename the admin directory to something different to do the normal rails setup (rake db:create, rake db:schema:load, rake db:seed) and then move the directory back into place.

@tobyhede
Contributor

+1 to this issue, hitting it in dev

@eliang
eliang commented Dec 4, 2011

+1. Is there a fix?

@leonels
leonels commented Dec 17, 2011

I try it to make cap deploy:migrations work, but got this error undefined method find_all' for nil:NilClass

@clintonb

@leonels Try the following

ActiveAdmin.routes(self) if (!$ARGV.nil? && $ARGV.find_all { |x| x =~ /migrate|rollback/i}.empty?)

@ognevsky

+1 on this bug

@ancorcruz

+1

Maybe you should use:

if ( File.basename($0) == "rake" and not ARGV.nil? and not ARGV.index{ |a| a =~ /^db:\w/i }.nil? )

to be ensure that all rake db commands run successfully (db:migrate, db:rollback, db:setup, db:migrate:reset and so on)

@harisadam

+1

@clintonb thanks, it's works!

@pcreux
Contributor
pcreux commented Feb 18, 2012

I can't reproduce this bug.

@pcreux pcreux closed this Feb 18, 2012
@jsmestad

I am having this issue as well. @pcreux this is fairly simple to reproduce, empty out your database and simply run bundle exec rspec. You should get DB errors for missing tables since ActiveAdmin.register(self) loads the environment and ActiveAdmin files in app/admin

/Users/justin/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/activerecord-3.2.3/lib/act
ive_record/connection_adapters/sqlite_adapter.rb:465:in `table_structure': Could not find ta
ble 'rails_challenge_categories' (ActiveRecord::StatementInvalid)
        from /Users/justin/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/activerecord-
3.2.3/lib/active_record/connection_adapters/sqlite_adapter.rb:346:in `columns'
        from /Users/justin/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/activerecord-
3.2.3/lib/active_record/connection_adapters/schema_cache.rb:12:in `block in initialize'
        from /Users/justin/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/activerecord-
3.2.3/lib/active_record/model_schema.rb:228:in `yield'
        from /Users/justin/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/activerecord-
3.2.3/lib/active_record/model_schema.rb:228:in `default'
        from /Users/justin/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/activerecord-
3.2.3/lib/active_record/model_schema.rb:228:in `columns'
        from /Users/justin/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/activerecord-
3.2.3/lib/active_record/model_schema.rb:237:in `columns_hash'
        from /Users/justin/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/activerecord-
3.2.3/lib/active_record/locking/optimistic.rb:129:in `locking_enabled?'
        from /Users/justin/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/activerecord-
3.2.3/lib/active_record/relation.rb:170:in `exec_queries'
        from /Users/justin/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/activerecord-
3.2.3/lib/active_record/relation.rb:160:in `block in to_a'
        from /Users/justin/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/activerecord-
3.2.3/lib/active_record/explain.rb:40:in `logging_query_plan'
        from /Users/justin/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/activerecord-
3.2.3/lib/active_record/relation.rb:159:in `to_a'
        from /Users/justin/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/activerecord-
3.2.3/lib/active_record/relation/finder_methods.rb:159:in `all'
        from /Users/justin/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/activerecord-
3.2.3/lib/active_record/querying.rb:5:in `all'
        from /Users/justin/Documents/cafewell/cwrails/app/admin/abstract_challenges.rb:36:in
 `block in <top (required)>'
        from /Users/justin/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/activeadmin-0
.4.4/lib/active_admin/dsl.rb:13:in `instance_eval'
        from /Users/justin/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/activeadmin-0
.4.4/lib/active_admin/dsl.rb:13:in `run_registration_block'
        from /Users/justin/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/activeadmin-0
.4.4/lib/active_admin/namespace.rb:178:in `parse_registration_block'
        from /Users/justin/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/activeadmin-0
.4.4/lib/active_admin/namespace.rb:54:in `register'
# ....
@alexandru-calinoiu

+1 for this issue

@alexandru-calinoiu

please reopen this since is very annoying

@michalorman

+1 happened to me just now

active admin 0.5.0

@cwoodcox
Contributor
cwoodcox commented Nov 8, 2012

This is still a problem. The issue lies here.

Basically, when we load all the app/admin/ files, we reference pretty much every model constant. If you've just generated a model and a migration, but haven't run it yet, and you create the file for the model in app/admin/, you'll reference the model during the Rails boot process. That's typically fine, Rails will go autoload the model file, but if the table doesn't exist yet, since the migration hasn't been run, it will raise an SQL exception, since part of initializing the ActiveRecord class involves asking the database for all the columns on that table.

So, just run your migrations, right? Wrong. The routes file gets included when booting the environment to run the rake task, which calls ActiveAdmin::Application.load!, which causes exactly what I described above while trying to run the migration to solve the problem you're having in the first place. Pretty frustrating.

I'm working on a solution, but I don't really like the things proposed above... Seems hacky.

Anyone like @pcreux or @gregbell got any ideas? I'm having this issue using the latest from this very repo.

@cwoodcox
Contributor
cwoodcox commented Nov 8, 2012

Okay, now I feel like a moron. Must be the time.

This is actually an exact duplicate of #1074, and (even more ironic) #1328, which I opened myself.

Maybe there should be some sort of documentation around this? Don't reference your model classes without making sure it won't get executed at boot-time? I don't see another way around it, since we have to load the configs at boot-time, unless the routing config changes.

I'm gonna shut up now before I put my foot in my mouth again. 🔫

@pranas
Contributor
pranas commented Nov 21, 2012

I think @fringd is going the right way to solve this issue. Check #783.

@rishav
rishav commented Dec 18, 2012

What do the authors have to say about this ?

@seanlinsley
Member

I'm not having this problem, as I just stated on #783. Can some one provide specific steps to recreate this problem? Maybe even upload an example rails app to GitHub.

@stestaub stestaub referenced this issue in hzamani/acts_as_relation May 7, 2013
Closed

Problem with migration #32

@lidaobing

+1 for reopen this bug

@shir
shir commented Jun 20, 2013

+1 for reopen this bug.
Same issue as described here hzamani/acts_as_relation#32

@seanlinsley
Member

What version of AA are you using? Because AA shouldn't ever touch the DB until one of these things occur:

  • an HTTP request hits /admin
  • you are directly accessing the DB somewhere in your app/admin/* files that isn't wrapped in a proc or block

The common examples of the second one are:

  • you're building dynamic scopes based on the values of a particular DB column
  • you are passing a :collection to a filter, but haven't wrapped it in a proc
@sigmaray

@Daxter We had met this issue in ActiveAdmin 0.6.0.

Here is sample app which reproduces this bug: https://github.com/sigmaray/aaissue. You can just run "rake db:migrate" to see an error. If you will remove app/admin/pens.rb migrations will run without problems.

@seanlinsley
Member

@sigmaray, @stestaub, @shir

After looking into the problem, the problem is that ActsAsRelation doesn't follow (what I believe to be) Rails conventions. Considering this:

$ rake db:migrate
rake aborted!
Could not find table 'products'
.../activerecord-3.2.13/lib/active_record/connection_adapters/sqlite_adapter.rb:472:in `table_structure'
.../activerecord-3.2.13/lib/active_record/connection_adapters/sqlite_adapter.rb:346:in `columns'
.../activerecord-3.2.13/lib/active_record/connection_adapters/schema_cache.rb:12:in `block in initialize'
.../activerecord-3.2.13/lib/active_record/model_schema.rb:228:in `yield'
.../activerecord-3.2.13/lib/active_record/model_schema.rb:228:in `columns'
.../activerecord-3.2.13/lib/active_record/model_schema.rb:254:in `content_columns'
.../acts_as_relation-0.1.2/lib/active_record/acts_as_relation.rb:100:in `included'
.../acts_as_relation-0.1.2/lib/active_record/acts_as_relation.rb:98:in `include'
.../acts_as_relation-0.1.2/lib/active_record/acts_as_relation.rb:98:in `block in acts_as'
.../acts_as_relation-0.1.2/lib/active_record/acts_as_relation.rb:97:in `class_eval'
.../acts_as_relation-0.1.2/lib/active_record/acts_as_relation.rb:97:in `acts_as'
.../aaissue/app/models/pen.rb:2:in `<class:Pen>'
.../aaissue/app/models/pen.rb:1:in `<top (required)>'

[ the app loads config/routes.rb, which causes AA to load the model definition ]

The problem is that ActsAsRelation assumes that the database has been migrated when the model is loaded. This is opposite to how Rails itself behaves, where everything relating to the DB is lazy.

# After disabling AA from the example app that @sigmaray set up:
# Expected:
AdminUser        # AdminUser(Table doesn't exist)
AdminUser.new    # ActiveRecord::StatementInvalid: Could not find table 'admin_users'
AdminUser.find() # ActiveRecord::StatementInvalid: Could not find table 'admin_users'

# Unusual:
Pen              # ActiveRecord::StatementInvalid: Could not find table 'products'

It's my opinion that ActsAsRelation is at fault here, not Active Admin.

@shir
shir commented Jun 26, 2013

@Daxter I think the main problem is that ActiveAdmin tries to access db in routes. It's wrong and this error is just consequence of accessing db in routes.

@seanlinsley
Member

You've got it backwards. It isn't Active Admin that tries to access the DB, it's ActsAsRelation.

@seanlinsley
Member

The problem is that ActsAsRelation is built in such a way that when you cause the Pen model to be loaded, it immediately queries the DB table of the class that pens are supposed to act like (products in this case).

@yellowaj
yellowaj commented Aug 1, 2013

I ran into this same problem while running migrations (locally and remotely) with ActiveAdmin.

I removed ActsAsRelation (based on @Daxter's insight), used the workaround from @clintonb, even commented out the ActiveAdmin and Devise routes - and still no luck.

It ended up being an issue with ActiveAdmin creating the seed AdminUser during the migration. Basically I had several gems referencing tables which had not been created yet. I simply moved the creation of the AdminUser to the seeds file (so I could control when it was run), re-ran my migrations, then seeded the db - worked lovely!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment