← all rules

require-not-null

warning

Nullable column (policy)

Why it's unsafe

A column has no NOT NULL constraint; this policy requires every column in a CREATE TABLE to be NOT NULL.

Safe rewrite

Add NOT NULL to the column (it is free on a new, empty table), or add it later in the same migration with ALTER TABLE ... ALTER COLUMN ... SET NOT NULL. For an intentionally nullable column, suppress with -- pgsafe:ignore require-not-null ....

Example

Try it in the playground →

Unsafe

CREATE TABLE users (id bigint PRIMARY KEY, email text);

Safe

CREATE TABLE users (id bigint PRIMARY KEY, email text NOT NULL);

Related