pgAdmin 4 will not let you edit rows in the data grid
Cells in View/Edit Data cannot be editedShort answer
pgAdmin edits a row only when it can find that exact row again. A table with no primary key or OID opens read-only, and a Query Tool result is editable only when it selects all primary key columns directly from one table, without renaming them. Add a primary key, or change the query.
Fix it fast
1Find out which cause you have
Check whether the table has a primary key.
SELECT conname FROM pg_constraint WHERE conrelid = 'public.my_table'::regclass AND contype = 'p';2Match what you see, then jump to its fix
What does the error look like?
Cells in View/Edit Data cannot be editedLock icons in the column headers of the Query Tool result
Cause 1 of 2
The table has no primary key
1Check
pgAdmin documents that a table without an OID or a primary key shows its data read-only, because rows cannot be told apart.
\d public.my_table2Fix
Add a primary key on a column that is unique and never null, then reopen the data grid. If no column fits, add an identity column.
ALTER TABLE public.my_table ADD PRIMARY KEY (id);
-- or, with no suitable column:
ALTER TABLE public.my_table ADD COLUMN id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY;3Verify
Open View/Edit Data again and double-click a cell.
-- the cell opens for editing; press Save Data to commitConfirmed by pgadmin.org
Cause 2 of 2
The Query Tool result is not an updatable result set
1Check
A result is editable only if all primary key columns of the table are selected. Only columns taken straight from the table are editable; renamed columns, columns selected twice and computed ones are read-only. Pencil and lock icons in the headers show which is which.
SELECT id, name AS title, upper(name) FROM public.my_table;2Fix
Select the primary key and the plain columns without aliases, from one table.
SELECT id, name, email FROM public.my_table WHERE id < 100;3Verify
The column headers now show pencil icons.
-- edit a cell, then press Save DataConfirmed by pgadmin.org
How do I stop it coming back?
- Give every table a primary key when you create it.
- Use the Query Tool for edits only on single-table queries that include the key columns.
- With auto-commit off, remember that saved edits stay in the open transaction until you commit it.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Related fixes
Databases
A table you created does not appear in the pgAdmin 4 browser tree
CREATE TABLE succeeded in the Query Tool, tree unchanged
The table usually exists; the tree is showing something else.
4 causes, each with a fixDatabases
DBeaver cannot run pg_restore: the utility is not found in the client home
Utility 'pg_restore' not found in client home '/usr/lib' (/usr/lib)
DBeaver runs pg_restore from a local PostgreSQL client folder; it does not bundle one.
3 causes, each with a fixDatabases
DBeaver cannot download the PostgreSQL driver from Maven
The PostgreSQL driver files are missing and the download does not complete
DBeaver downloads the PostgreSQL JDBC driver from a Maven repository the first time you connect.
3 causes, each with a fixDatabases
python manage.py migrate finishes but the tables for my app are missing
relation "myapp_book" does not exist
migrate only applies migration files that exist.
3 causes, each with a fixDatabases
Django save fails on PostgreSQL: null value in a column violates a not-null constraint
django.db.utils.IntegrityError: null value in column "price" of relation "shop_product" violates not-null constraint
A model field is NOT NULL in the database unless it has null=True.
3 causes, each with a fixDatabases
Django migration on PostgreSQL stops with 'pending trigger events'
django.db.utils.OperationalError: cannot ALTER TABLE "mytable" because it has pending trigger events
PostgreSQL runs a Django migration in one transaction.
2 causes, each with a fix