【问题标题】:Drupal error when creating table创建表时的Drupal错误
【发布时间】:2018-07-25 07:49:24
【问题描述】:

我正在尝试在 .install 模块中创建一个新表,这就是我所做的:

$schema['commission_summary'] = array (
  'description' => 'Récapitulatif des commissions',
      'fields' => array(
           'commission_summary_id' => array(
              'description' => 'ID de commission',
              'type' => 'serial',
              'unsigned' => TRUE,
              'not null' => TRUE,
           ),
          'product_id' => array(
              'description' => 'ID du produit lié',
              'type' => 'int',
              'not null' => TRUE,
              'default' => 0,
          ),
          'date_depart' => array(
              'description' => 'Date du debut du voyage',
              'type' => 'int',
              'not null' => TRUE,
              'default' => 0,
          ),
          'prestataire' => array(
              'description' => 'ID du partenaire lié (Agence)',
              'type' => 'int',
              'not null' => TRUE,
              'default' => 0,
          ),
          'nb_participant_total' => array(
              'description' => 'Nombre de participants total',
              'type' => 'int',
              'not null' => TRUE,
              'default' => 0,
          ),
          'nb_participant_agence' => array(
              'description' => 'Nombre de participants de l\'agence ',
              'type' => 'int',
              'not null' => TRUE,
              'default' => 0,
          ),
      ),
      'primary key' => array('commission_summary_id'),
      'indexes' => array(
          'product_id' => array('product_id'),
          'partner_id' => array('prestataire')
      ),
  );
return $schema;

function ga_commission_update_7101() {
  $table = 'commission_summary';
  $schema = drupal_get_schema_unprocessed('commission_summary', $table);
  db_create_table('commission_summary', $schema);
}

问题是我得到一个错误但我不知道为什么,我的语法看起来不错?

我创建了其他类似的表,所以我不明白为什么这次它不起作用

这是我得到的错误:

Failed: PDOException : SQLSTATE[42000]: Syntax error or access violation: 
1064 You have an error in your SQL syntax; check the manual that 
corresponds to your MariaDB server version for the right syntax to use 
near ') ENGINE = InnoDB DEFAULT CHARACTER SET utf8' at line 1: CREATE 
TABLE {commission_summary} ) ENGINE = InnoDB DEFAULT CHARACTER SET utf8; 
Array ( ) dans db_create_table() (ligne 2776 dans 
/var/www/clients/client1/web84/web/includes/database/database.inc).

【问题讨论】:

    标签: database pdo drupal


    【解决方案1】:

    您需要在您的 hook_update_n 中定义您的表,这将起作用:

     function ga_commission_update_7101() {
         $table = array(
            'description' => 'Récapitulatif des commissions',
            'fields' => array(
              'commission_summary_id' => array(
                'description' => 'ID de commission',
                'type' => 'serial',
                'unsigned' => TRUE,
                'not null' => TRUE,
              ),
              'product_id' => array(
                'description' => 'ID du produit lié',
                'type' => 'int',
                'not null' => TRUE,
                'default' => 0,
              ),
              'date_depart' => array(
                'description' => 'Date du debut du voyage',
                'type' => 'int',
                'not null' => TRUE,
                'default' => 0,
              ),
              'prestataire' => array(
                'description' => 'ID du partenaire lié (Agence)',
                'type' => 'int',
                'not null' => TRUE,
                'default' => 0,
              ),
              'nb_participant_total' => array(
                'description' => 'Nombre de participants total',
                'type' => 'int',
                'not null' => TRUE,
                'default' => 0,
              ),
              'nb_participant_agence' => array(
                'description' => 'Nombre de participants de l\'agence ',
                'type' => 'int',
                'not null' => TRUE,
                'default' => 0,
              ),
            ),
            'primary key' => array('commission_summary_id'),
            'indexes' => array(
              'product_id' => array('product_id'),
              'partner_id' => array('prestataire')
            ),
          );
    
          db_create_table('commission_summary', $table);
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-17
      • 2015-04-18
      • 2010-11-03
      • 1970-01-01
      相关资源
      最近更新 更多