Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion docusaurus/docs/cms/backend-customization/models.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,20 @@ Database validations and settings are custom options passed directly onto the `t
| `defaultTo` | string | Sets the database `defaultTo`, typically used with `notNullable` | - |
| `notNullable` | boolean | Sets the database `notNullable`, ensures that columns cannot be null | `false` |
| `unsigned` | boolean | Only applies to number columns, removes the ability to go negative but doubles maximum length | `false` |
| `unique` | boolean | Enforces database level unique, caution when using with draft & publish feature | `false` |
| `unique` | boolean | Enforces database-level uniqueness on published entries. Draft saves skip the check when Draft & Publish is enabled, so duplicates fail only at publish time. | `false` |
| `type` | string | Changes the database type, if `type` has arguments, you should pass them in `args` | - |
| `args` | array | Arguments passed into the Knex.js function that changes things like `type` | `[]` |

:::caution Draft & Publish and `unique`
When [Draft & Publish](/cms/features/draft-and-publish) is enabled, Strapi intentionally skips `unique` validations while an entry is saved as a draft. Duplicates therefore remain undetected until publication, at which point the database constraint triggers an error even though the UI previously displayed “Saved document” for the drafts.

To avoid unexpected publication failures:

- disable Draft & Publish on content-types that must stay globally unique,
- or add custom validation (e.g. lifecycle hooks or middleware) that checks for draft duplicates before saving,
- or rely on automatically generated unique identifiers such as a `uid` field and document editorial conventions.
:::

```json title="./src/api/[api-name]/content-types/restaurant/schema.json"

{
Expand Down