简体   繁体   中英

Active_admin running an error when run rake db:migrate

I'm trying to install ActiveAdmin under Rails 4 to generate my admin panel.

I added the gem and installed with the below commands:

gem 'activeadmin', github: 'gregbell/active_admin'
bundle install
rails g active_admin:install              # creates the AdminUser class
rails g active_admin:install User         # uses an existing class

But when I try to migrate I get an error:

$ rake db:migrate
==  AddDeviseToAdminUsers: migrating ==========================================
-- change_table(:admin_users)
rake aborted!
An error has occurred, this and all later migrations canceled:

SQLite3::SQLException: duplicate column name: email: ALTER TABLE "admin_users" ADD "email" varchar(255) DEFAULT '' NOT NULL/usr/local/rvm/gems/ruby-2.0.0-p247/gems/sqlite3-1.3.8/lib/sqlite3/database.rb:91:in `initialize'

As mentioned in issue 753 on github I changed the AddDeviseToAdminUsers migration from change_table to create_table but that results in this error:

==  AddDeviseToAdminUsers: migrating ==========================================
-- create_table(:admin_users)
rake aborted!

Can anyone help please?

The exception you're seeing is due to a migration conflicting with your existing database structure. Your admin_users table already contains an "email" column, which is why you're seeing the error duplicate column name: email .

You should only run the active_admin:install generator once . Running the ActiveAdmin setup with a clean application should only involve the following:

# Add the BETA gem with Rails 4 support. The ActiveAdmin master
# branch is still in heavy development.
gem 'activeadmin', github: 'gregbell/active_admin'

# Bundle
bundle install

# Setup ActiveAdmin 
rails g active_admin:install

For more advanced cases, where you already have an ActiveRecord model for an admin user then you'd use this variant of the generator: rails g active_admin:install MyAdminUser

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM