저는 현재 michael hartl의 레일 3 튜토리얼에서 루비 작업을하고 있습니다. db : migrate를 호출하려고하면이 문제가 발생합니다. 누군가가 내가 왜 낙담하는지 알아낼 수있게 도와 줄 수 있을까? 감사!레이크 중단되었습니다, add_index (: users, : email, {: unique => true})
** 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")
CODE
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+\-.][email protected][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
난 정말 레일을 사용하는 것이 처음이므로 정확히 무슨 뜻인지 확실하지 않습니다. – AustinT
@AustinTruong 데이터베이스에는 동일한 전자 메일이있는 사용자 레코드가 있습니다. 이것은 마이그레이션하는 동안 오류의 원인입니다. 데이터베이스의 중복 된 전자 메일을 삭제하거나 변경하면 마이그레이션을 실행할 수 있습니다. –
고맙습니다. 실제로 문제를 일으킨 이메일의 중복 된 항목이었습니다. sqlite db 브라우저를 사용하여 항목을 제거한 다음 스크립트를 다시 실행했습니다. – noobcode