如何重置主键(??)我想将我的主键设置为translate_str,让它在表中是唯一的,但我已经创建了表并在数据库中有很多日期。 我的简要代码在https://gist.github.com/poc7667/6076745谢谢你:)
How to reset primary key (??) I wanna set my primary key to translate_str , let it be unique in the table, But I've already create the table and have lots of date in the database. My Brief code is at https://gist.github.com/poc7667/6076745 Thanks you :)
最满意答案
如果您在translate_str列中有多个具有相同值的条目,那么更改表以使translate_str 唯一将给您一个错误。
如果收到错误,请删除重复记录,然后再次更改。
为了唯一性,您还可以使用Rails模型验证:
validates_uniqueness_of :translate_strPS。 数据库中的UNIQUE属性优于validates_uniqueness_of。 如果两个请求同时由rails处理,则有时validates_uniqueness_of可能会失败。
If you have multiple entries with the same value in translate_str column, then altering your table to make translate_str unique will give you an error.
If you receive an error, remove duplicate records then do the altering again.
For uniqueness you can also use Rails model validation:
validates_uniqueness_of :translate_strPS. UNIQUE attribute in database is better than validates_uniqueness_of. Cause validates_uniqueness_of might fail sometimes if two requests handled by rails at the same time.
更多推荐
发布评论