Table definition:
CREATE TABLE `demo` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(32) NOT NULL DEFAULT '',
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4;
Model definition:
<?php
class Demo extends Model
{
public function getSource()
{
return 'demo';
}
public function initialize()
{
$this->useDynamicUpdate(true);
}
}
Test Code:
<?php
$demo = new Demo();
$demo->name = 'hello';
try {
$demo->save();
$demo->name = 'world';
$demo->save(); //this line throw an exception with message: created_at is required
} catch (\Exception $e) {
echo $e->getMessage();
}
I confuse with it. Is this normal?