我正在尝试在.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).
答案 0 :(得分:0)
您需要在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);
}