Rake Aborted , on add_index(:users, :email, {:unique=>true})

前端 未结 1 1048
旧巷少年郎
旧巷少年郎 2021-01-20 17:51

I am currently working on ruby on rails 3 tutorial by michael hartl. I am running into this problem when I try to call db:migrate. Could someone help me figure out why its a

相关标签:
1条回答
  • 2021-01-20 18:38

    Nothing wrong with your migration. The error simply means you have existing email duplicates data in db.

    Check your users table, set unique emails for existing rows or delete these rows. Then run the migration again.

    Update: Please note that even if you remove the unique constraint from migration and add validates_uniqueness_of :email to your Active Model, the problem would still eat you in the future.

    The root problem is your data is in a 'bad' state. If you have two rows having the same email address (or it's also possible they both have blank email), after adding validates_uniqueness_of :email your User model instance for these two rows won't be valid. So it's still a data problem you have to fix.

    0 讨论(0)
提交回复
热议问题