我在drupal7中创建了Schema
$schema['survey'] = array(
'description' => 'TODO: please describe this table!',
'fields' => array(
'id' => array(
'description' => 'TODO: please describe this field!',
'type' => 'serial',
'not null' => TRUE,
),
'survey_id' => array(
'description' => 'TODO: please describe this field!',
'type' => 'int',
'not null' => FALSE,
....
'record_date' => array(
'description' => 'TODO: please describe this field!',
'mysql_type' => 'timestamp',
'not null' => FALSE,
),
'facebookid' => array(
'description' => 'TODO: please describe this field!',
'type' => 'varchar',
'length' => '10',
'not null' => FALSE,
)
/**
* hook_enable()
*/
function itg_be_lucky_today_enable() {
db_query('
ALTER TABLE {survey}
MODIFY record_date TIMESTAMP NOT NULL
DEFAULT CURRENT_TIMESTAMP
ON UPDATE CURRENT_TIMESTAMP'
);
}
当我尝试启用模块时,它显示错误:
PDOException: SQLSTATE[42000]: Syntax error or access violation: 1067 Invalid default value for 'record_date': CREATE TABLE {survey} ( `id` INT NOT NULL auto_increment COMMENT 'TODO: please describe this field!', `survey_id` INT NULL DEFAULT NULL COMMENT 'TODO: please describe this field!', `name` VARCHAR(100) NULL
我已经搜索过,但没有找到任何解决方案。
这在我的本地计算机上工作正常。 我还测试了mysql版本:5.7和5.5
由于
答案 0 :(得分:0)
试试这个:
'record_date' => array(
'description' => 'TODO: please describe this field!',
'type' => 'datetime',
'mysql_type' => 'datetime',
'not null' => FALSE,
),
有关更详细的答案,请参阅this post