requiredfields and primary key.

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
mangakissa_events
Posts: 7
Joined: Fri 05 Feb 2016 11:38

requiredfields and primary key.

Post by mangakissa_events » Fri 19 Feb 2016 11:16

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?

ViktorV
Devart Team
Posts: 3168
Joined: Wed 30 Jul 2014 07:16

Re: requiredfields and primary key.

Post by ViktorV » Fri 19 Feb 2016 14:26

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

Post Reply