Skip to main content

当启用草稿与发布时,status 不能作为属性名称使用

🌐 status cannot be used as an attribute name when Draft & Publish is enabled

在 Strapi 5 中,status 是 Document Service API 和 REST API 用来区分草稿和已发布内容的保留参数。在启用草稿与发布的内容类型中,如果用户自定义了同名的属性 status,将会导致命名冲突。

🌐 In Strapi 5, status is the reserved parameter used by the Document Service API and REST API to distinguish draft and published content. A user-defined attribute also named status on a Draft & Publish-enabled content type causes a naming collision.

此页面是重大更改数据库的一部分,提供关于重大更改的信息以及从 Strapi v4 迁移到 Strapi 5 的附加说明。

🌐 This page is part of the breaking changes database and provides information about the breaking change and additional instructions to migrate from Strapi v4 to Strapi 5.

 Is this breaking change affecting plugins?Yes
 Is this breaking change automatically handled by a codemod?No

重大变更描述

🌐 Breaking change description

在 Strapi v4 中

启用了草稿和发布的内容类型可以具有名为 status 的用户定义属性。该属性名称与使用 publicationState 参数的发布工作流之间不存在冲突。

🌐 Content types with Draft & Publish enabled can have a user-defined attribute named status. No conflict exists between this attribute name and the publication workflow, which uses the publicationState parameter.

在 Strapi 5 中

status 是 Draft & Publish 的保留查询参数(它取代了 publicationState)。在启用了 Draft & Publish 的内容类型上定义名为 status 的用户属性会导致命名冲突。Strapi 5 对此限制的执行如下:

  • 内容类型构建器: 阻止在启用了“草稿与发布”的任何内容类型上创建 status 属性。同样,也阻止在已经有 status 属性的内容类型上启用“草稿与发布”。
  • 服务器启动: 当检测到 status 属性与草稿和发布同时存在时,会记录一次警告(每个内容类型 UID 一次)。服务器会继续启动,因此现有项目不会被破坏。

迁移

🌐 Migration

本节重新组合了有关引入的重大更改的有用说明和程序。

🌐 This section regroups useful notes and procedures about the introduced breaking change.

注意

🌐 Notes

  • status 属性名称也是 Strapi 5 中全局保留名称的更大列表的一部分。完整列表请参见 某些属性和内容类型名称是保留的
  • 此重大更改增加了上下文特定的限制:只有在内容类型启用“草稿与发布”时,才会强制执行 status 冲突。
  • 有关 status 参数如何用于查询草稿和已发布内容的详细信息,请参阅 Draft & Publish

手动操作

🌐 Manual procedure

如果内容类型具有 status 属性并且启用了草稿与发布(或你打算启用它),请在启用草稿与发布之前重命名 status 属性。

🌐 If a content type has a status attribute and Draft & Publish is enabled (or you intend to enable it), rename the status attribute before enabling Draft & Publish.

  1. 在内容类型构建器中,打开具有 status 属性的内容类型。
  2. status 属性重命名为非保留名称(例如,approval_statusworkflow_state)。
  3. 点击保存以应用模式更改。
  4. 更新任何引用旧 status 属性名称的查询、控制器、服务、策略或前端代码。
  5. 如果“草稿和发布”被阻止启用,请在内容类型的高级设置选项卡中重新启用它。