,这里是我当前的用户模式:问题与安装设计
# == Schema Information
#
# Table name: users
#
# id :integer not null, primary key
# first_name :string
# last_name :string
# created_at :datetime not null
# updated_at :datetime not null
#
require 'elasticsearch/model'
class User < ActiveRecord::Base
searchkick word_start: [:user]
has_many :posts
validates :first_name, :last_name, presence: true
end
这些都是我能够在问题出现之前要经过的步骤抬起了头:
rails generate devise:install
rails generate devise user
rake db:migrate
一次我尝试迁移它,这是什么出现:
== 20160707230510 AddDeviseToUsers: migrating =================================
-- change_table(:users)
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:
PG::DuplicateColumn: ERROR: column "email" of relation "users" already exists
: ALTER TABLE "users" ADD "email" character varying DEFAULT '' NOT NULL
/Users/aa/Documents/railsy/basicProject/db/migrate/20160707230510_add_devise_to_users.rb:5:in `block in up'
/Users/aa/Documents/railsy/basicProject/db/migrate/20160707230510_add_devise_to_users.rb:3:in `up'
ActiveRecord::StatementInvalid: PG::DuplicateColumn: ERROR: column "email" of relation "users" already exists
: ALTER TABLE "users" ADD "email" character varying DEFAULT '' NOT NULL
/Users/aa/Documents/railsy/basicProject/db/migrate/20160707230510_add_devise_to_users.rb:5:in `block in up'
/Users/aa/Documents/railsy/basicProject/db/migrate/20160707230510_add_devise_to_users.rb:3:in `up'
PG::DuplicateColumn: ERROR: column "email" of relation "users" already exists
/Users/aa/Documents/railsy/basicProject/db/migrate/20160707230510_add_devise_to_users.rb:5:in `block in up'
/Users/aa/Documents/railsy/basicProject/db/migrate/20160707230510_add_devise_to_users.rb:3:in `up'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
正如你可以从我以前的用户架构告诉,没有邮件列那里。所以...为什么这个错误出现?
**编辑 - 应该已经发布了色器件迁移文件 - 不工作的一个**
class AddDeviseToUsers < ActiveRecord::Migration
def self.up
change_table :users do |t|
## Database authenticatable
t.string :email, null: false, default: ""
t.string :encrypted_password, null: false, default: ""
## Recoverable
t.string :reset_password_token
t.datetime :reset_password_sent_at
## Rememberable
t.datetime :remember_created_at
## Trackable
t.integer :sign_in_count, default: 0, null: false
t.datetime :current_sign_in_at
t.datetime :last_sign_in_at
t.inet :current_sign_in_ip
t.inet :last_sign_in_ip
## Confirmable
# t.string :confirmation_token
# t.datetime :confirmed_at
# t.datetime :confirmation_sent_at
# t.string :unconfirmed_email # Only if using reconfirmable
## Lockable
# t.integer :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts
# t.string :unlock_token # Only if unlock strategy is :email or :both
# t.datetime :locked_at
# Uncomment below if timestamps were not included in your original model.
# t.timestamps null: false
end
add_index :users, :email, unique: true
add_index :users, :reset_password_token, unique: true
# add_index :users, :confirmation_token, unique: true
# add_index :users, :unlock_token, unique: true
end
def self.down
# By default, we don't want to make any assumption about how to roll back a migration when your
# model already existed. Please edit below which fields you would like to remove in this migration.
raise ActiveRecord::IrreversibleMigration
end
end
再次编辑
当我运行rails g devise user
...这是什么来up:
Running via Spring preloader in process 72318
invoke active_record
create db/migrate/20160707230510_add_devise_to_users.rb
insert app/models/user.rb
route devise_for :users
可能你的方案已经过时了,但是在你的数据库的表中如果有一个字段。您可以重命名字段电子邮件迁移'db/migrate/2016xxxxxx_devise_create_users.rb'并再次运行('bundle exec rake db:migrate')。 – kalelc
@kalec,我的模式不过时。它根本没有电子邮件列。我知道。 =) – user273072545345
@kalelc,我原来的用户架构没有它......但我只是用设计迁移文件更新了我的帖子,我无法运行......因此它的错误......它列出了电子邮件字段在那...但为什么它尖叫重复让我困惑... – user273072545345