[PyQt] QSqlTableModel doesn't know submitted records any more with PostgreSQL database

Sibylle Koczian nulla.epistola at web.de
Wed Feb 11 19:26:13 GMT 2015


Hello,

when I insert data into a PostgreSQL database table using a 
QSqlTableModel they are written to the database, but I can't see them in 
the appliction after submitting. This happens with tables whose primary 
key has type SERIAL, it doesn't happen if the primary key is inserted by 
hand.

This doesn't happen with SQLite databases and it doesn't happen if I use 
PyQt4.

I've attached a small example which uses the following tables:

CREATE TABLE states
(
   cc character(2) NOT NULL,
   name character varying(50) NOT NULL,
   CONSTRAINT states_pkey PRIMARY KEY (cc)
)

CREATE TABLE towns
(
   id serial NOT NULL,
   name character varying(50) NOT NULL,
   cc character(2) NOT NULL,
   CONSTRAINT towns_pkey PRIMARY KEY (id),
   CONSTRAINT towns_cc_fkey FOREIGN KEY (cc)
       REFERENCES states (cc) MATCH SIMPLE
       ON UPDATE NO ACTION ON DELETE NO ACTION,
   CONSTRAINT towns_name_cc_key UNIQUE (name, cc)
)

Running the application on Windows 7, using Python 3.4.2, PyQt 5.4 gives 
the following output:

Result using SQLite (5 states, 7 towns before starting):

d:\home\...\pyqt5_sql>statoids_model_cons.py lite
New state, example: HE Hessen: NI Niedersachsen
DEBUG:__main__:Before submit, new record in row 6: Niedersachsen (NI)
DEBUG:__main__:After submit, new record in row 6: Niedersachsen (NI)
New town in NI: Düsseldorf
DEBUG:__main__:Before submit, new record in row 8: Düsseldorf in NI, PK 0
DEBUG:__main__:After submit, new record in row 8: Düsseldorf in NI, PK 9
BW: Baden-Württemberg
...
NI: Niedersachsen
1: Frankfurt in HE
...
9: Düsseldorf in NI
DEBUG:__main__:Model data created and shown

Everything as expected.

Result using PostgreSQL 9.4 (1 state, 1 town before starting):

d:\home\...\pyqt5_sql>statoids_model_cons.py pg
New state, example: HE Hessen: NI Niedersachsen
DEBUG:__main__:Before submit, new record in row 1: Niedersachsen (NI)
DEBUG:__main__:After submit, new record in row 1: Niedersachsen (NI)
New town in NI: Düsseldorf
DEBUG:__main__:Before submit, new record in row 1: Düsseldorf in NI, PK 0
DEBUG:__main__:After submit, new record in row 1: None in None, PK None ***
HE: Hessen
NI: Niedersachsen
1: Frankfurt in HE
None: None in None ***
DEBUG:__main__:Model data created and shown

Lines with *** show the problem, I think. The new record gets into the 
database, but it can be important to see it in the application.

What can I do? Can this be a bug in QPSQL?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: statoids_model_cons.py
Type: text/x-script.phyton
Size: 4507 bytes
Desc: not available
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20150211/7537ba80/attachment.bin>


More information about the PyQt mailing list