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

2

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

  

AN OCCURRED ERROR:

     

Column: "Name" contains null values.

I use the PGADMIN III version.

    
asked by anonymous 01.04.2015 / 15:01

1 answer

2

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

  • You are creating a new column and you are not putting a DEFAULT value in it. This way it can be null. Set a% cos_de% value that ensures non-nullity if nothing is passed. If you do not want to keep this default , then you can give DEFAULT .
  • 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 enforce this constraint for the column all rows need to conform to it. Before you have to solve the problem of the lines before you can apply the new constraint. There is no way for the database to solve this alone, you have to take action, you have to put valid values in this column on all the rows contained in the table. After this the constraint can be applied because all lines can handle it.
  • 01.04.2015 / 15:05