← all rules

require-primary-key

warning

Table without a primary key

Why it's unsafe

This table is created without a primary key. Logical replication needs one (a table with no replica identity rejects UPDATE/DELETE), and many ORMs and tools assume every table has one.

Safe rewrite

Add a primary key — inline (PRIMARY KEY on a column, or a table-level PRIMARY KEY (...)) or in a later ALTER TABLE ... ADD PRIMARY KEY in the same migration.

Example

Try it in the playground →

Unsafe

CREATE TABLE events (id int, payload jsonb);

Safe

CREATE TABLE events (id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY, payload jsonb);

Related