【问题标题】:Change the value of a field in Rails Sqlite via terminal通过终端更改 Rails Sqlite 中字段的值
【发布时间】:2014-08-27 09:53:48
【问题描述】:

如何使用终端/命令行更改 Rails 表中的值? 例如,我有一个表“users”,其中一个字段 admin 设置为“false”,我想通过终端将其更改为 true - 如下所示:

 update users set admin = true where email = joe@example.com

【问题讨论】:

    标签: sql ruby-on-rails sqlite terminal


    【解决方案1】:

    假设 Rails 4:

    user = User.find_by email: "joe@example.com"
    user.update!(admin: true)
    

    【讨论】:

      【解决方案2】:

      使用rails c:

      user = User.where(email: "joe@example.com").first
      user.update_coluns(admin: true)
      

      或者,例如多个条目:

      User.where(email: "joe@example.com").update_all(admin: true)
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-06-30
        • 2022-07-12
        • 2011-05-29
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-07-27
        相关资源
        最近更新 更多