generator rails_admin:install tries to access table "users" before migration #1196

Closed
Knack opened this Issue Jun 8, 2012 · 4 comments

Projects

None yet

2 participants

@Knack

After generating a devise model for users, the rails_admin generator tries to access the new users table before running the migration. Maybe the solution is to run the 'db:migrate' task from inside the rails_admin generator after calling the devise generator.

Here is the full trace:

rails g rails_admin:install
           -  Hello, RailsAdmin installer will help you sets things up!
           -  I need to work with Devise, let's look at a few things first:
           -  Checking for a current installation of devise...
           -  Found it!
           -  Looks like you've already installed it, good!
           ?  What would you like the user model to be called? Press <enter> for [user] > 
           -  Now setting up devise with user model name 'user':
    generate  devise
      invoke  active_record
      create    db/migrate/20120608130434_devise_create_users.rb
      create    app/models/user.rb
      insert    app/models/user.rb
       route  devise_for :users
           -  Now you'll need an initializer...
      create  config/initializers/rails_admin.rb
[...]/gems/activerecord-3.2.2/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:243:in `query': Mysql2::Error: Table 'project_development.users' doesn't exist: SHOW FULL FIELDS FROM `users` (ActiveRecord::StatementInvalid)
    from [...]/gems/activerecord-3.2.2/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:243:in `block in execute'
    from [...]/gems/activerecord-3.2.2/lib/active_record/connection_adapters/abstract_adapter.rb:280:in `block in log'
    from [...]/gems/activesupport-3.2.2/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
    from [...]/gems/activerecord-3.2.2/lib/active_record/connection_adapters/abstract_adapter.rb:275:in `log'
    from [...]/gems/activerecord-3.2.2/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:243:in `execute'
    from [...]/gems/activerecord-3.2.2/lib/active_record/connection_adapters/mysql2_adapter.rb:211:in `execute'
    from [...]/gems/activerecord-3.2.2/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:257:in `execute_and_free'
    from [...]/gems/activerecord-3.2.2/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:424:in `columns'
    from [...]/gems/activerecord-3.2.2/lib/active_record/connection_adapters/schema_cache.rb:12:in `block in initialize'
    from [...]/gems/activerecord-3.2.2/lib/active_record/model_schema.rb:228:in `yield'
    from [...]/gems/activerecord-3.2.2/lib/active_record/model_schema.rb:228:in `default'
    from [...]/gems/activerecord-3.2.2/lib/active_record/model_schema.rb:228:in `columns'
    from [...]/gems/rails_admin-0.0.4/lib/rails_admin/adapters/active_record.rb:83:in `properties'
    from [...]/gems/rails_admin-0.0.4/lib/rails_admin/config/fields.rb:50:in `factory'
    from [...]/gems/rails_admin-0.0.4/lib/rails_admin/config/has_fields.rb:129:in `_fields'
    from [...]/gems/rails_admin-0.0.4/lib/rails_admin/config/has_fields.rb:127:in `_fields'
    from [...]/gems/rails_admin-0.0.4/lib/rails_admin/config/has_fields.rb:107:in `all_fields'
    from [...]/gems/rails_admin-0.0.4/lib/rails_admin/config/has_fields.rb:82:in `fields'
    from (erb):85:in `block in template'
    from (erb):82:in `map'
    from (erb):82:in `template'
    from [...]/ruby-1.9.3-p194/lib/ruby/1.9.1/erb.rb:838:in `eval'
    from [...]/ruby-1.9.3-p194/lib/ruby/1.9.1/erb.rb:838:in `result'
    from [...]/gems/thor-0.14.6/lib/thor/actions/file_manipulation.rb:111:in `block in template'
    from [...]/gems/thor-0.14.6/lib/thor/actions/create_file.rb:54:in `call'
    from [...]/gems/thor-0.14.6/lib/thor/actions/create_file.rb:54:in `render'
    from [...]/gems/thor-0.14.6/lib/thor/actions/create_file.rb:63:in `block (2 levels) in invoke!'
    from [...]/gems/thor-0.14.6/lib/thor/actions/create_file.rb:63:in `open'
    from [...]/gems/thor-0.14.6/lib/thor/actions/create_file.rb:63:in `block in invoke!'
    from [...]/gems/thor-0.14.6/lib/thor/actions/empty_directory.rb:114:in `call'
    from [...]/gems/thor-0.14.6/lib/thor/actions/empty_directory.rb:114:in `invoke_with_conflict_check'
    from [...]/gems/thor-0.14.6/lib/thor/actions/create_file.rb:61:in `invoke!'
    from [...]/gems/thor-0.14.6/lib/thor/actions.rb:95:in `action'
    from [...]/gems/thor-0.14.6/lib/thor/actions/create_file.rb:26:in `create_file'
    from [...]/gems/thor-0.14.6/lib/thor/actions/file_manipulation.rb:110:in `template'
    from [...]/gems/rails_admin-0.0.4/lib/generators/rails_admin/install_generator.rb:59:in `install'
    from [...]/gems/thor-0.14.6/lib/thor/task.rb:22:in `run'
    from [...]/gems/thor-0.14.6/lib/thor/invocation.rb:118:in `invoke_task'
    from [...]/gems/thor-0.14.6/lib/thor/invocation.rb:124:in `block in invoke_all'
    from [...]/gems/thor-0.14.6/lib/thor/invocation.rb:124:in `each'
    from [...]/gems/thor-0.14.6/lib/thor/invocation.rb:124:in `map'
    from [...]/gems/thor-0.14.6/lib/thor/invocation.rb:124:in `invoke_all'
    from [...]/gems/thor-0.14.6/lib/thor/group.rb:226:in `dispatch'
    from [...]/gems/thor-0.14.6/lib/thor/base.rb:389:in `start'
    from [...]/gems/railties-3.2.2/lib/rails/generators.rb:170:in `invoke'
    from [...]/gems/railties-3.2.2/lib/rails/commands/generate.rb:12:in `<top (required)>'
    from [...]/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:251:in `require'
    from [...]/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:251:in `block in require'
    from [...]/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:236:in `load_dependency'
    from [...]/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:251:in `require'
    from [...]/gems/railties-3.2.2/lib/rails/commands.rb:29:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'
@mshibuya
Collaborator

This is strange.
What do you have in your Gemfile?

@Knack

I'm not sure, I've made many changes since then.
I'm using "mysql2" as the database adapter.

I think the problem was:

  • I installed devise but I didn't generate a model
  • Rails Admin then calls "generate devise" to create model User
  • Devise generates the model User, but don't run the migration
  • Rails Admin continues with the creation of the the initializer rails_admin.rb and tries to access the User's table but it doesn't exist yet, because the migration is not done.

My solution was to run rake db:migrate and then run again rails_admin:install

@mshibuya
Collaborator

Confirmed.
It surely gives the error by following your instruction.

@mshibuya
Collaborator

Fixed in 0.6.1, probably due to 1aed17d.

@mshibuya mshibuya closed this Feb 25, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment