mysql - 'record_date' 时间戳的默认值无效

标签 mysql drupal drupal-7 drupal-modules

我已经在 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/

相关文章:

php - 代码点火器 : View Table Data from Double Relation Table

python - 更新函数不更新表条目

php - 德鲁帕尔 8 : how can I add a class in form tag

mysql - 无法连接到本地主机数据库

javascript - setVisible 不适用于 <option>

php - 我正在使用 php 作为后端在 android 中进行推送通知。如何将我的 Sql 数据库值检索到 android 中

html - 页脚无法正常工作

css - Drupal Zen 主题中使用的 float 侧边栏方法

linux - Drupal 7 文件权限

Drupal 7 批处理页面示例