We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

$obj->save() == false return "serial is required"

hi,

i have simply code:

PostgreSQL:

> CREATE TABLE comments

> (

> id serial NOT NULL,

> owner integer,

> type character(1),

> created timestamp without time zone,

> message text,

> CONSTRAINT comments_pkey PRIMARY KEY (id)
> )

model is autogenerated and Controller:

> 
> $comment= new Comments();

> $comment->message=$msg;

> $comment->owner=$uid;

> $comment->type=$type;

> $comment->created=date('Y-m-d h:i:s.u');

> 

> if ($comment->save() == false) {

> 

>     foreach ($comment->getMessages() as $value) {

>         echo $value.'; \n';

>     }

> }

return this: id is required

someone know why? other saves to tables work fine...

using Phalcon DevTools (1.3.4)

Ok im had the same error, occur when you have two columns of serial type or when you have two default value column with some sequence added, also you set null to id, ex: $comment->id = null;



7.6k

ok, but i have only one autoincremented column... nothing else... simpliest from simpliest :P

edited Mar '15

Check if this serial was created sequence, something like php comment_id_seq and this seq and if really increment it value, also verify the column id if was add default value something like:

nextval('name_seq_comments_id_seq'::regclass)


7.6k

thank for replay. Actualy i havent access to DB, i check afternoon.

Yes, i using PgAdmin, why?