Error creating a NOT NULL field in PGADMIN " contains null values "

Asked

Viewed 523 times

2

I have a database already created, within it I have a table already created. In it I need to create a field that is NOT NULL. I do everything by the graphical interface that is faster, I click on the table > new column :, I name it, name it and mark it NOT NULL. When I check the NOT NULL option and click OK, save appears the following error:

AN ERROR OCCURRED:

Column: "Name" contains null values.

I use the version of PGADMIN III.

1 answer

2


The message itself gives a good indication of the problem. Two things can happen:

  1. You are creating a new column and you are not placing a value DEFAULT in it. In this way it can be null. Establish a value DEFAULT that guarantees non-nullity if nothing is passed. If you do not want to keep this default, then you can give a DROP DEFAULT.
  2. You are transforming a column that accepted values and nulls and in fact there are these values in some of the rows contained in the table. When you want to impose this restriction on the column all rows need to be in accordance with it. First you need to solve the problem of the lines to then be able to apply the new restriction. There is no way the database can solve this alone, you have to take action, you have to put valid values in this column in all the rows contained in the table. After this the restriction can be applied because all lines can serve it.
  • Oops, thank you for the answer. But that’s not it, I’m creating a new column, it didn’t exist before and there’s no null data in a column that’s created at the moment.

  • See if you can handle it now.

  • Yes, that way I can insert a new field like NOT NULL. Thank you

  • @Do you know that you can also vote on the answers? Not only on the questions you asked, you can vote on everything on website. See the [tour]. It would be nice for you to review at least everything you’ve posted and see if what you posted deserves your vote.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.