私は現在、michael hartl による ruby on rails 3 チュートリアルに取り組んでいます。db:migrate を呼び出そうとすると、この問題が発生します。誰かがなぜそれが中止されたのかを理解するのを手伝ってくれませんか. ありがとう!
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Invoke db:load_config (first_time)
** Execute db:load_config
** Execute db:migrate
== AddEmailUniquenessIndex: migrating ========================================
-- add_index(:users, :email, {:unique=>true})
rake aborted!
An error has occurred, this and all later migrations canceled:
SQLite3::ConstraintException: indexed columns are not unique: CREATE UNIQUE INDEX "index_users_on_email" ON "users" ("email")
コード
class AddEmailUniquenessIndex < ActiveRecord::Migration
def up
add_index :users, :email, :unique => true
end
def down
remove_index :users, :email
end
end
ユーザーコード
# == Schema Information
#
# Table name: users
#
# id :integer not null, primary key
# name :string(255)
# email :string(255)
# created_at :datetime not null
# updated_at :datetime not null
#
class User < ActiveRecord::Base
attr_accessor :password
attr_accessible :email, :name, :password, :password_confirmation
email_regex = /\A[\W+\-.]+@[a-z\d\-.]+\.|[a-z]+\z/i
validates :name, :presence => true,
:length => { :maximum => 50 }
validates :email, :presence => true,
:format => { :with => email_regex },
:uniqueness => { :case_sensitive => false }
validates :password, :presence => true,
:confirmation => true,
:length => { :within => 6..40 }
end