Bug report #12386

NOT NULL problem on PostGIS tables

Added by Seb Radzimski over 9 years ago. Updated over 9 years ago.

Status:Closed
Priority:Normal
Assignee:-
Category:Data Provider/PostGIS
Affected QGIS version:2.8.1 Regression?:No
Operating System:windows/ubuntu Easy fix?:No
Pull Request or Patch supplied:No Resolution:
Crashes QGIS or corrupts data:No Copied to github as #:20560

Description

Hi.
I have a problem with not null serial field in QGIS 2.8 on Windows (7/8) and Linux (Ubuntu 12.04).
Database is PostgreSQL 9.3 with PostGIS 2 on that Ubuntu.
If I create table like:

CREATE TABLE null_test
( gid serial NOT NULL,  id serial NOT NULL,  aaa text,  bbb text,  ccc real,
  the_geom geometry(Geometry,2177),
  CONSTRAINT null_test_pkey PRIMARY KEY (gid),
  CONSTRAINT enforce_geotype_the_geom CHECK (geometrytype(the_geom) = 'LINESTRING'::text OR the_geom IS NULL)
);

and load it in QGIS (as a postgres user) I wont be able to add any object because of id NOT NULL constraint. When I add a new feature QGIS shows in Feature Attributes nextval(‘null_test_id_seq’::regclass) in id field (as for gid) but while saving says:
Could not commit changes to layer null_test
Errors: ERROR: 1 feature(s) not added.
Provider errors:
PostGIS error while adding features: ERROR: null value in column "id" violates not-null constraint Failing row contains (4, null, null, null, null, 00B3...)

I've notes also that if I delete primary key constraint from gid QGIS 2.8 won't be able to get new value from gid sequence and display the same kind of error for gid field.
The same table ‘null_test’ loaded in QGIS 2.6 works fine.
I have attached some printscreen to show what I mean.
Can you help?
Cheers!

01.PNG (139 KB) Seb Radzimski, 2015-03-17 12:18 AM

02.PNG (156 KB) Seb Radzimski, 2015-03-17 12:18 AM


Related issues

Related to QGIS Application - Bug report #12391: Postgres character(n) default values not properly handled... Closed 2015-03-17

Associated revisions

Revision bfb8ab68
Added by Jürgen Fischer over 9 years ago

edit widgets: keep default values of new feature's attributes until they are added
(fixes #12391 & #12386)

Revision 4c3cf64f
Added by Jürgen Fischer almost 9 years ago

edit widgets: keep default values of new feature's attributes until they are added
(fixes #12391 & #12386 & #13857)

(cherry picked from commit bfb8ab6893d5bf77b4ae92c6c90e0b5b9c7e9ae7)

History

#1 Updated by Seb Radzimski over 9 years ago

  • Assignee deleted (Jürgen Fischer)

#2 Updated by Jürgen Fischer over 9 years ago

  • Status changed from Open to Closed

Also available in: Atom PDF