I have a problem with inserting new QSqlRecord to Postgresql database. Target table is defined as follows:
create table samochod(
samochod_id integer primary key default nextval('samochod_id_seq'),
marka varchar(30),
poj_silnika numeric,
typ_silnika silnik_typ,
liczba_osob smallint
);
And code of record insertion is:
QSqlRecord rec = model->record();
rec.setGenerated("samochod_id", false);
rec.setValue("marka", ui.brandEdit->text());
rec.setValue("poj_silnika", ui.volSpin->value());
rec.setValue("typ_silnika", ui.engineCombo->currentText());
rec.setValue("liczba_osob", ui.passengersSpin->value());
bool ok = model->insertRecord(-1,rec);
All I want to do is insert a new record, and make sql set its samochod_id
for me, but despite I set isGenerated
to false it crashes with message:
"ERROR: null value in column "samochod_id" violates not-null constraint
QPSQL: Unable to create query"
What should I do to make QSqlRecord leave generation of samochod_id
to database?