PG::NotNullViolation error on id column in PostgreSQL

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;