Page 1 of 1

requiredfields and primary key.

Posted: Fri 19 Feb 2016 11:16
by mangakissa_events
I have a database on MariaDB version 5.5.32. This table is created:

Code: Select all

CREATE TABLE nelisnw.setjes (
  id int(11) NOT NULL,
  jaar varchar(4) NOT NULL,
  week varchar(2) NOT NULL,
  expediteur_logistiek varchar(8) NOT NULL,
  splitscode smallint(6) NOT NULL,
  zuurcontrole varchar(8) NOT NULL,
  preparatie varchar(2) NOT NULL,
  notitie varchar(20) NOT NULL,
  verkooporderID int(11) DEFAULT NULL,
  setnr int(11) DEFAULT NULL,
  PRIMARY KEY (id))
I've set the TMyQuery.Options.Requiredfields to true. So var so good.
When I want to save the record, field ID wants to have an value, because it's required. But field ID is primary key and the database has to create an unique number. If I set field ID to required = false, the database stores the field ID as 0.

How can I use this option feature and let the database create an unique number?

Re: requiredfields and primary key.

Posted: Fri 19 Feb 2016 14:26
by ViktorV
In order to automatically generate a value for the primary key, you should add the AUTO_INCREMENT attribute on its declaration. For example:

Code: Select all

  id int(11) NOT NULL  AUTO_INCREMENT