我想设置更新属性以获取应用程序的更新时间。这是我的模型代码:
public function createDatabase() {
$testdatabase = "testdatabase";
$this->dbforge->create_database($testdatabase);
$this->db->db_select($testdatabase);
$fields = array(
'id' => array(
'type' => 'INT',
'constraint' => 1,
'unsigned' => TRUE,
),
'name' => array(
'type' => 'VARCHAR',
'constraint' => '100',
),
'establishment_date' => array(
'type' => 'VARCHAR',
'constraint' => '50',
'null' => TRUE,
),
'package' => array(
'type' => 'VARCHAR',
'constraint' => '15',
),
'db_name' => array(
'type' => 'VARCHAR',
'constraint' => '25',
),
'update_date' => array(
'type' => 'datetime',
'on update' => 'NOW()',
),
'upgrade' => array(
'type' => 'tinyint',
'constraint' => '1',
'default' => '0',
),
'status' => array(
'type' => 'tinyint',
'constraint' => '1',
'default' => '4',
),
);
$this->dbforge->add_field($fields);
$this->dbforge->add_field("subscription_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP");
$this->dbforge->add_field("subscription_expire TIMESTAMP DEFAULT '0000-00-00 00:00:00'");
$this->dbforge->add_key('id', TRUE);
$this->dbforge->create_table('tms_profile');
}
表已成功创建,但名为update_date的字段上不存在更新属性。我想在该字段上设置更新atrributes。
答案 0 :(得分:2)
您所要做的就是更改type
列的update_date
,如
....
'update_date' => array(
'type' => 'TIMESTAMP'
),
.....
现在它将使用NOW()
答案 1 :(得分:0)
使用内联声明,例如:
`update_stamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP',