Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在尝试从 Rails 控制台中删除我的数据库中的多条记录。我知道我可以做 User.find(1).destroy。如果我想删除 ID 为 100 - 200 的所有用户怎么办。有没有办法在控制台中执行此操作?
你可以做类似的事情User.delete_all("id > 100 AND id < 200")。
User.delete_all("id > 100 AND id < 200")
Rails 5 中的新语法是 Mischa 在他的评论中提到的语法:User.where("id > 100 AND id < 200").delete_all
User.where("id > 100 AND id < 200").delete_all
delete_all在 rails 5.1 中将不推荐使用传递条件。
delete_all