我已经在 drupal7 中创建了架构
$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
谢谢
最佳答案
试试这个:
'record_date' => array(
'description' => 'TODO: please describe this field!',
'type' => 'datetime',
'mysql_type' => 'datetime',
'not null' => FALSE,
),
更详细的答案请参阅this post
关于mysql - 'record_date' 时间戳的默认值无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44111969/