I have this migration:
public function up(){
$this->dbforge->add_field([
'id'=>['type'=>'int', 'unique'=>true, 'unsigned'=>true,'auto_increment'=>true],
'email'=>['type'=>'varchar', 'constraint'=>200, 'null'=>true],
'password'=>['type'=>'varchar', 'constraint'=>250],
'created_at'=>['type'=>'datetime', 'default' => 'CURRENT_TIMESTAMP'],
]);
$this->dbforge->add_key('id', TRUE);
$this->dbforge->create_table('users', TRUE);
}
I am trying to set table with column created_at
with default value - current datetime.
I am using 'default' => 'CURRENT_TIMESTAMP'
, but I am getting this error:
Invalid default value for 'created_at' .... NOT NULL,
created_at
datetime NOT NULL DEFAULT 'CURRENT_TIMESTAMP',
I am using CodeIgniter 3
with MySQL
.
'created_at'=>['type'=>'datetime', 'default' => 'CURRENT_TIMESTAMP']
try'created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP'
- – Illconditionedcreated_at
will becreated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
and remove array (with type, and default) in this key. – Barina