database - 创建表时的Drupal错误
问题描述
我正在尝试在 .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).
解决方案
您需要在 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);
}
推荐阅读
- bash - git - 使用用户名和密码将参数传递给 git
- python - Pytorch 如何在多个进程之间共享内存?
- c - 使用 sigaction、SIGKILL 和警报处理程序杀死耗时超过 3 秒的分叉进程
- angularjs - AngularJS 中的视图单元测试问题
- haskell - Haskell 中的唯一 ID/计数器
- aws-pinpoint - 如何使用 Pinpoint 创建深度链接推送通知?
- python - 有谁知道如何将 sqllite 中数据库上的列提取到数组中?
- c# - SQLKata 动态 Where 子句
- jquery - 我无法触发 Wicket onchange 事件
- json - 如何使用 LibGDX 写入 JSON 文件中的一个值