lundi 7 décembre 2015

CakePHP 3 - saving entities id/created/modified not filled in using sqlite

I've worked with cake 1 & 2 in the past, first time I'm using cakephp 3.

I tried to do something fairly simple, connect to an sqlite database and create a record.

I wanted the id, created and modified fields to be automatically filled in. It might be because I'm using sqlite and the table definition is wrong, normally I use mysql or postgres.

My table:

CREATE TABLE account (
    id       CHAR (36) PRIMARY KEY
    username TEXT      UNIQUE,
    password TEXT      NOT NULL,
    created  INTEGER,
    modified INTEGER
);

And what I'm doing to save data in it:

$account = new Account([
    'username' => $username,
    'password' => $password
]);
TableRegistry::get('Account')->save($account);

I've been reading the docs and for id a char(36) should have done the job like it is mentioned here: http://ift.tt/1IztaPP

Aucun commentaire:

Enregistrer un commentaire