AutoIncrement for field

Issue #220 resolved
Максим Сысоев created an issue

Hello. I'm using ORM Marshmallow. I connect to MySql server with FireDAC and generate model by ORM:

 [Entity]
  [Table('Custumer')]
  TpsCustomer = Class
  private
    [AutoGenerated]
    [Column('SID', [cpRequired, cpNotNull, cpPrimaryKey])]
    FId: Integer;
    FLastName: String;
    FFirstName: String;
    FMiddleName: String;
    FExLastName: String;
    FBirthDay: Nullable<TDate>;
    FIsWoman: Byte;
    FNational: String;
    [Column('DocID', [], 50)]
    FDocID: Integer;
    [ManyToOne(False, [ckCascadeAll], 'FDocID')]
    FDocument: TpsDocument;
  public
    destructor Destroy; override;
    property ID: Integer read FId;
    [ColumnAttribute('lastName', [], 50, 'Фамилия')]
    property LastName: String read FLastName write FLastName;
    [Column('firstName', [], 50, 'Имя')]
    property FirstName: String read FFirstName write FFirstName;
    [Column('middleName', [], 50, 'Отчество')]
    property MiddleName: String read FMiddleName write FMiddleName;
    [Column('exLastName', [], 50, 'Предыдущая фамилия')]
    property ExLastName: String read FExLastName write FExLastName;
    [Column('birthDay', [], 50, 'Дата рождения')]
    property BirthDay: Nullable<TDate> read FBirthDay write FBirthDay;
    [Column]
    property IsWoman: Byte read FIsWoman write FIsWoman;
    [Column('National', [], 50, 'National')]
    property National: String read FNational write FNational;
    property DocID: Integer read FDocID write FDocID;
    property Document: TpsDocument read FDocument write FDocument;

When I insert new item in table and commit - give this exception:

First chance exception at $745124C2. Exception class EMySQLNativeException with message '[FireDAC][Phys][MySQL] Field 'SID' doesn't have a default value'. Process APM_Passport.exe (7292)

How set default value (Auto_Increment) to field SID?

Thanks, and sorry for my eng.

Comments (6)

  1. Максим Сысоев reporter

    Is it possible to set the property (auto_increment) using attributes and TDatabaseManager.BuildDatabase? Or to do it manually?

  2. Stefan Glienke repo owner

    Yes, implementing DoGenerateCreateTable in TMySQLGenerator - it currently uses the ANSI implementation which does not know about the AUTO_INCREMENT.

  3. Log in to comment