PG::NotNullViolation error on id column in PostgreSQL
By Pierre-Alain B on Sunday, September 17 2017, 03:30 - Permalink
Faced with this error:
PG::NotNullViolation: ERROR: null value in column "id" violates not-null constraint
it took me some time to realize that my id column was not a serial but a plain integer...
To fix this, just execute:
ALTER TABLE my_table DROP COLUMN id; ALTER TABLE my_table ADD COLUMN id SERIAL PRIMARY KEY;