Skip to content

PGRST106: "The schema must be one of the following..." error when querying an exposed schema

当你尝试通过你最近公开的 PostgREST API 查询某个模式时,可能会遇到 PGRST106 错误,提示 {"code":"PGRST106","message":"The schema must be one of the following: public"}

🌐 You may encounter a PGRST106 error, stating {"code":"PGRST106","message":"The schema must be one of the following: public"}, when attempting to query a schema via the PostgREST API that you've recently exposed.

为什么会发生这种情况: 这个错误是因为 authenticator 角色的 pgrst.db_schemas 设置中没有包括所需的 schema。这就导致了冲突,因为 PostgREST 依赖这个设置来知道它应该暴露哪些 schemas。

如何解决此问题: 要解决此问题,你需要更新 authenticator 角色的 pgrst.db_schemas 设置。连接到你的数据库并执行以下其中一个 SQL 命令:

  • 要显式添加你的模式: 如果你想在现有模式(例如 public)之外添加你特定的模式(例如 your_schema_name),可以使用以下命令。记得将 your_schema_name 替换为你的实际模式名称,并包括所有已定义的其他必要模式。 ALTER ROLE authenticator SET pgrst.db_schemas = 'public, your_schema_name';
  • 要重置为仪表板配置 你也可以重置此设置,以便 Supabase 仪表板的配置自动生效。 ALTER ROLE authenticator RESET pgrst.db_schemas;