我之前看过这个问题,但那里的解决方案对我不起作用。 Rake Aborted , on add_index(:users, :email, {:unique=>true}) 在Michael Hartl的Rails教程中,他希望你add_index:name,:email,unique:true我不断收到此错误消息。
$ bin / rake db:migrate RAILS_ENV = test
DL is deprecated, please use Fiddle
== 20141224060705 AddIndexToUsers: migrating ==================================
-- add_index(:users, :email, {:unique=>true})
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:
SQLite3::ConstraintException: indexed columns are not unique: CREATE UNIQUE INDE
X "index_users_on_email" ON "users" ("email")c:/Sites/example/db/migrate/2014122
4060705_add_index_to_users.rb:3:in `change'
c:in `migrate'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
数据库中没有用户。这是数据库的图片
答案 0 :(得分:0)
您必须将要添加索引的属性包含在数组中,如下所示:
add_index :users, [:name, :email], unique: true
第一个参数是表名,第二个参数可以是属性数组或单个属性,然后是一些选项。
希望这有帮助!