Ruby Rails 无法更新 pg 数据库 table 值

Ruby on Rails can't update pg database table values

出于某种原因,我无法使用新值更新数据库 table,每次我尝试更新时都会抛出 table 错误。

table 架构如下

  create_table "some_users", id: false, force: :cascade do |t|
    t.string "id", limit: 255
    t.string "user_id", limit: 255
    t.string "member_id", limit: 255
    t.string "panel_id", limit: 255
    t.string "country_code", limit: 255
    t.boolean "is_subscribed"
    t.datetime "updated_at"
    t.datetime "created_at", default: -> { "CURRENT_TIMESTAMP" }
  end

模型定义为:

class SomeUser < ApplicationRecord
end

尝试更新 table 时生成的错误是:

some_user = SomeUser.find_by(member_id: newPanelistId)
some_user.update(country_code: "DE")



ActiveRecord::StatementInvalid - PG::SyntaxError: ERROR:  zero-length delimited identifier at or near """"
LINE 1: ...ers" SET "country_code" = 'DE' WHERE "some_users"."" IN (SEL...

Ruby 版本为:ruby 2.7.1p83

Rails版本:Rails5.2.3

按以下方式更改模型即可解决问题

class SomeUser < ApplicationRecord
    self.primary_key = "id"
end