任何帮助都会很棒。
function request_gold_pack_schema() {
$schema['request_gold_pack_customer_details'] = array(
'description' => 'Table to store all customer details.',
'fields' => array(
'rid' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'auto increment' => TRUE
),
'title' => array(
'type' => 'varchar',
'length' => 10,
'not null' => TRUE,
'default' => ''
),
'first_name' => array(
'type' => 'varchar',
'length' => 50,
'not null' => TRUE,
'default' => ''
),
'last_name' => array(
'type' => 'varchar',
'length' => 50,
'not null' => TRUE,
'default' => ''
),
'house_name_no' => array(
'type' => 'varchar',
'length' => 50,
'not null' => TRUE,
'default' => ''
),
'street' => array(
'type' => 'varchar',
'length' => 160,
'not null' => TRUE,
'default' => ''
),
'town' => array(
'type' => 'varchar',
'length' => 50,
'not null' => TRUE,
'default' => ''
),
'county' => array(
'type' => 'varchar',
'length' => 50,
'not null' => TRUE,
'default' => ''
),
'telephone' => array(
'type' => 'int',
'length' => 12,
'not null' => TRUE,
'default' => ''
),
'email' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => ''
),
'date_registered' => array(
'mysql_type' => 'DATETIME',
'not null' => TRUE
),
'primary' => array(
'rid'
)
)
);
return $schema;
}
给了我以下错误
注意:未定义的索引:在DatabaseSchema_mysql-> processField()中输入(/Users/richardskinner/Sites/www.goldrushmoney.com-local/httpdocs/includes/database/mysql/schema.inc的第205行)。 注意:未定义的索引::在DatabaseSchema_mysql-> processField()中的正常(/Users/richardskinner/Sites/www.goldrushmoney.com-local/httpdocs/includes/database/mysql/schema.inc的第205行)。 PDOException:SQLSTATE [42000]:语法错误或访问冲突:1064 SQL语法中有错误;查看与您的MySQL服务器版本对应的手册,以便在'DEFAULT NULL'附近使用正确的语法)ENGINE = InnoDB DEFAULT CHARACTER SET utf8 COMMENT'Table to stor'at line 13:CREATE TABLE {request_gold_pack_customer_details}(
rid
INT NOT NULL DEFAULT 0,title
VARCHAR(10)NOT NULL DEFAULT'',first_name
VARCHAR(50)NOT NULL DEFAULT'',last_name
VARCHAR(50)NOT NULL DEFAULT'',house_name_no
VARCHAR(50)NOT NULL DEFAULT'',street
VARCHAR(160)NOT NULL DEFAULT'',town
VARCHAR(50)NOT NULL DEFAULT'',county
VARCHAR(50)NOT NULL DEFAULT'',telephone
INT NOT NULL DEFAULT'',date_registered
DATETIME NOT NULL,{{1} } DEFAULT NULL)ENGINE = InnoDB DEFAULT CHARACTER SET utf8 COMMENT'表存储所有客户详细信息。'; db_create_table()中的Array()(/ Users/richardskinner/Sites/www.goldrushmoney.com-local/httpdocs/includes/database/database.inc的第2688行)。
试图找到解决方案几个小时。
感谢。
答案 0 :(得分:2)
这是您主键的问题。你把它列在fields数组中(它不应该是),它应该被引用为'primary key'而不是'primary',如下所示:
function request_gold_pack_schema(){
$schema['request_gold_pack_customer_details'] = array(
'description' => 'Table to store all customer details.',
'fields' => array(
// Your field definitions
),
'primary key' => array(
'rid'
)
);
return $schema;
}
查看drupal.org上的schema api documentation。
我还建议将rid
字段设置为serial
,然后不要使用自动增量参数(Drupal会处理)。因此'rid'字段定义如下:
'rid' => array(
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
)
答案 1 :(得分:0)
你必须在drupal 7中为'int'类型指定大小...即
'rid' => array(
'type' => 'int',
'not null' => TRUE,
'size' => 'normal',
'auto increment' => TRUE,
),
尺寸可以是正常的,小的,大的 检查drupal 7数据类型。