Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

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"


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:


Use $connection->insert()