运行rake db:migrate时,Active_admin运行错误

时间:2013-11-12 13:25:47

标签: ruby-on-rails devise activeadmin

我正在尝试在Rails 4下安装ActiveAdmin以生成我的管理面板。

我添加了gem并使用以下命令安装:

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

但是当我尝试迁移时出现错误:

$ 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'

正如issue 753 on github中所述,我将AddDeviseToAdminUsers迁移从change_table更改为create_table,但这会导致此错误:

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

有人可以帮忙吗?

1 个答案:

答案 0 :(得分:1)

您看到的异常是由于迁移与您现有的数据库结构冲突造成的。您的admin_users表已包含"电子邮件"列,这就是您看到错误duplicate column name: email

的原因

您应该只运行active_admin:install生成器一次。使用干净的应用程序运行ActiveAdmin设置应该只涉及以下内容:

# 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

对于更高级的情况,您已经拥有管理员用户的ActiveRecord模型,那么您将使用此生成器的变体:rails g active_admin:install MyAdminUser