下面是我的代码,请告诉我哪里错了..
public function up(){
$this->dbforge->add_field(array(
'id'=> array(
'type' => 'int',
'constraint' => 11,
'auto_increment'=> TRUE,
),
'ip_address'=> array(
'type' => 'VARCHAR',
'constraint'=> '40',
),
'login'=> array(
'type' => 'VARCHAR',
'constraint'=> '50',
),
'time'=> array(
'type' => 'timestamp',
'Default' => 'CURRENT_TIMESTAMP',
'ON UPDATE CURRENT_TIMESTAMP' => TRUE,
),
));
$this->dbforge->add_key('id',TRUE);
$this->dbforge->create_table('login_attempts');
echo "table created";
}
并且此错误将在运行迁移时生成
错误编号:
1067
“时间”的默认值无效
创建表login_attempts ( id int(11) NOT NULL AUTO_INCRMENT, ip_address VARCHAR(40) NOT NULL, 登录 VARCHAR(50) NOT NULL, 时间 时间戳 NOT NULL DEFAULT 'CURRENT_TIMESTAMP', CONSTRAINT pk_login_attempts 主键(id) ) 默认字符集 = utf8 整理 = utf8_general_ci
文件名:D:/xampp/htdocs/tank_auth/system/database/DB_driver.php
线路号码:691
查看
time
列的默认值。在 MySQL 中,CURRENT_TIMESTAMP
不得使用单引号。由于 CodeIgniter 出于安全原因会自动转义默认值,因此您也可以传递整个字符串,例如:
'time TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP',
将其他列保留为数组。仅更改时间列,如上所示。