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

Model create bug

Model create() two times like this:

$model->create(array('name' => 'Han', 'year' => '1989')); $model->create(array('name' => 'Zhang', 'year' => '1996'));

It occurred an error:"Record cannot be created because it already exists"



8.1k

May be your tables has unique key. Check this.

CREATE TABLE IF NOT EXISTS mytable ( id int(10) NOT NULL AUTO_INCREMENT, name varchar(70) NOT NULL, year int(11) NOT NULL, PRIMARY KEY (id) );

You can attach a logger to the database connections to see what SQL statements are being executed by the ORM: https://docs.phalcon.io/en/latest/reference/db.html#logging-sql-statements



5.4k
Accepted
answer

Use $connection->insert()