无法更新 Supabase 表,因为它没有副本标识

Sho*_*orn 3 supabase

当尝试使用 Supabase 更新我的第一个表时,代码如下:

await db.from("welcome").update({visit_count: newCount});
Run Code Online (Sandbox Code Playgroud)

出现错误:

{
  "hint":"To enable updating the table, set REPLICA IDENTITY using ALTER TABLE.",
  "details":null,"code":"55000",
  "message":"cannot update table \"welcome\" because it does not have a replica identity and publishes updates"
}
Run Code Online (Sandbox Code Playgroud)

Sho*_*orn 5

在本例中,问题是我创建的welcome表没有主键。

这个错误实际上与 Supabase 没有任何关系,它是与逻辑复制相关的 Postgres 错误: https: //pgdash.io/blog/postgres-replication-gotchas.html

有几个解决方案:

  • 确保您有主键列
  • 使用该alter table命令将一组特定的列设置为replica identity
  • 使用命令将alter table设为。replica identityfull