Drupal 7更新架构中断

时间:2016-09-21 21:34:26

标签: drupal-7 schema updates

有人能告诉我,我是否错过了这个?它会在代码块之后不断抛出底部提到的错误。

function license_update_7101() {

  $schema['license_agreements'] = array(
    'description' => 'License User Agreements',
    'fields' => array(
      'license_id' => array(
        'description' => 'Primary key for license records',
        'type'        => 'serial',
        'not null'    => TRUE,
        'unsigned'    => TRUE
      ),
      'user_id' => array(
        'description' => 'License agreed to by User ID',
        'type'        => 'int',
        'not null'    => FALSE,
        'unsigned'    => TRUE,
        'default'     => '0'
      ),
      'product_id' => array(
        'description' => 'Product ID that represents the product this agreement was assigned to.',
        'type'        => 'int',
        'not null'    => FALSE,
        'unsigned'    => TRUE,
        'default'     => '0'
      ),
      'session' => array(
        'description' => 'Session created during account creation.',
        'type'        => 'varchar',
        'length'      => 32,
        'not null'    => FALSE,
        'default'     => ''
      ),
      'agreed' => array(
        'description' => 'Represents if the license was agreed to or not',
        'type'        => 'int',
        'size'        => 'tiny',
        'not null'    => FALSE,
        'unsigned'    => TRUE,
        'default'     => '0'
      ),
      'agreement_date' => array(
        'description' => 'Date this license was agreed to by user.',
        'type'        => 'datetime',
        'mysql_type'  => 'DATETIME',
        'disp-width'  => '11',
        'not null'    => FALSE,
        'default'     => NULL
      ),
      'blog_name' => array(
        'description' => 'URL for actual product license belongs to.',
        'type'        => 'varchar',
        'length'      => '128',
        'not null'    => FALSE,
        'default'     => ''
      ),
      'primary key' => array('license_id')
    )
  );

  db_create_table('license_agreements', $schema['license_agreements']);
}

ERROR:

SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB    [error]
server version for the right syntax to use near 'DEFAULT NULL
) ENGINE = InnoDB DEFAULT CHARACTER SET utf8 COMMENT 'License' at line 9

真的很想解决这个问题。

谢谢!

1 个答案:

答案 0 :(得分:0)

所以,由于有另一个开发人员的帮助,我试图找到令人兴奋的东西,我设法在我们完成它的过程中发现了这个问题。

'primary key' => array('license_id')

我最终注意到它嵌入在字段数组中,需要在它之外/之后。

因此,修复就像将该行作为license_agreements数组的数组元素向下移动一样简单。问题解决了!