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.

One thought on “PostgreSQL — ERROR: column “” contains null values

Leave a Reply

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

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

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s