PostgreSQL — ERROR: column “” contains null values

If you’re adding or modifying a column in Postgres and you get this error, maybe it’s because you are changing a type to NOT NULL but the column already exists, with null values, or you’re adding one and the default is in fact NULL. That means you have to specify a default value for the field.

For example, I just added an integer field to a table called newsletter_newsletter:

ALTER TABLE newsletter_newsletter ADD COLUMN opened integer NOT NULL default 0;

Sometimes, I forget.

PostgreSQL is a sleeping giant that will one day break and destroy me. I just sit here hoping it runs smoothly, forever.


1 Comment

  1. Chris says:

    Google led me here when searching for ‘column contains null values’. Adding ‘default 0’ cleared that up for me. Thanks!!

Leave a Comment

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s