Drupal 7 hook_schema 没有安装数据库表 [英] Drupal 7 hook_schema not installing database table
问题描述
任何帮助都会很棒.
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' 附近使用正确的语法,第 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 '', email
VARCHAR(255) NOT NULL DEFAULT '', date_registered
DATETIME NOT NULL, primary
DEFAULT NULL ) ENGINE = InnoDB DEFAULT CHARACTER SET utf8 COMMENT 'Table存储所有客户详细信息.';db_create_table() 中的数组 ()(/Users/richardskinner/Sites/www.goldrushmoney.com-local/httpdocs/includes/database/database.inc 的第 2688 行).
Notice: Undefined index: type in DatabaseSchema_mysql->processField() (line 205 of /Users/richardskinner/Sites/www.goldrushmoney.com-local/httpdocs/includes/database/mysql/schema.inc). Notice: Undefined index: :normal in DatabaseSchema_mysql->processField() (line 205 of /Users/richardskinner/Sites/www.goldrushmoney.com-local/httpdocs/includes/database/mysql/schema.inc). PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '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,primary
DEFAULT NULL ) ENGINE = InnoDB DEFAULT CHARACTER SET utf8 COMMENT 'Table to store all customer details.'; Array ( ) in db_create_table() (line 2688 of /Users/richardskinner/Sites/www.goldrushmoney.com-local/httpdocs/includes/database/database.inc).
几个小时以来一直在寻找解决方案.
Been trying to find a solution for hours.
谢谢.
推荐答案
你的主键有问题.您已将其列在字段数组中(不应该如此),并且应将其引用为主键"而不是主键",如下所示:
It is an issue with your primary key. You hve it listed in the fields array (it should not be) and it should be referenced as 'primary key' and not 'primary', like so:
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;
}
查看 schema api 文档 在 drupal.org 上.
Check out the schema api documentation on drupal.org.
我还建议将 rid
字段设置为键入 serial
并保留自动增量参数(Drupal 将处理该参数).所以摆脱"字段定义是这样的:
I would also recommend setting the rid
field to type serial
and leaving off the auto increment parameter (Drupal will handle that). So the 'rid' field definitions would be as such:
'rid' => array(
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
)
这篇关于Drupal 7 hook_schema 没有安装数据库表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!