[英]Rails validates_uniqueness_of not working on MySQL
I am running MySQL 5.7 and Rails 6. The problem is that Rails is permitting duplicates even though I am using validates_uniqueness_of
.我正在运行 MySQL 5.7 和 Rails 6。问题是 Rails 允许重复,即使我使用的是validates_uniqueness_of
。
So for example:例如:
validates_uniqueness_of :email, if: :email_changed?
This will allow an email of USER@domain.com as well as user@domain.com.这将允许 USER@domain.com 和 user@domain.com 的 email。
I didn't know this option existed so I wanted to share with anyone else looking!我不知道这个选项存在,所以我想与其他人分享!
validates_uniqueness_of :email, case_sensitive: false, if: :email_changed?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.