Drupal 6模块安装文件未在数据库中创建表
我正在使用 Schema API 在 Drupa 6.17 上为我的模块创建表,但这些表并未在数据库中创建。我安装了架构模块,它告诉我,虽然我的模块的架构被识别,但它的表不在数据库中。它出现在“缺失”下:
Tables in the schema that are not present in the database.
test
* test_table
以下是我的 test.install 文件的内容。
<?php
// $Id$
function test_schema() {
$schema['test_table'] = array(
'description' => t('Test table'),
'fields' => array(
'nid' => array(
'description' => t('test field'),
'type' => 'serial',
'not null' => TRUE,
),
'options' => array(
'description' => t('other test field'),
'type' => 'text',
'not null' => FALSE,
),
),
'primary key' => array('nid'),
);
return $schema;
}
function test_install() {
drupal_install_schema('test');
}
function test_uninstall() {
drupal_uninstall_schema('test');
}
I'm using the Schema API to create tables for my module on Drupa 6.17, but the tables just do not get created in the database. I have the Schema module installed, and it tells me that while the schema for my module is recognized, its table is not in the database. It comes up under Missing:
Tables in the schema that are not present in the database.
test
* test_table
Here are the contents for my test.install file.
<?php
// $Id$
function test_schema() {
$schema['test_table'] = array(
'description' => t('Test table'),
'fields' => array(
'nid' => array(
'description' => t('test field'),
'type' => 'serial',
'not null' => TRUE,
),
'options' => array(
'description' => t('other test field'),
'type' => 'text',
'not null' => FALSE,
),
),
'primary key' => array('nid'),
);
return $schema;
}
function test_install() {
drupal_install_schema('test');
}
function test_uninstall() {
drupal_uninstall_schema('test');
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果您想在模块创建后添加模块安装,您需要从 drupal 数据库的系统表中删除记录,然后再次启用它。
禁用您的模块并保存
转到“系统”表并在那里找到您的模块
删除该记录
启用您的模块并保存
if you want to add module install after the module creation you need to remove the record from system table in your drupal db, and then enable it again.
disable your module and save
goto 'system' table and find your module there
remove that record
enable your module and save
编辑:
这是我刚刚编写的有效代码。如下示例:
Edit:
Here is code I just wrote that works. Follow as example:
当您第一次启用模块时,Drupal 仅运行该模块的 hook_install() 一次。除非您执行并禁用、卸载,然后重新启用该模块,否则您的模块的 hook_install() 会再次被调用。
如果您已经创建了模块的发行版并且想要向现有安装添加架构,那么您将需要添加调用 db_create_table() 的 hook_update_N() 的实现。
Drupal only runs a module's hook_install() once when you first enable the module. Unless you go through and disable, uninstall, and then re-enable the module will your module's hook_install() get called ever again.
If you had already created a release of your module and are wanting to add a schema to existing installs, you will want to add an implementation of hook_update_N() that calls db_create_table().
我想与您分享我在 Drupal 6 上遇到此错误的经验。在我的第一个模块中,我有三个表。我在我的
hook_schema
中为每个条目都有一个条目(称为education_schema
):在我的
hook_install
中,我最初有以下内容:没有在以下位置创建表模块安装。为什么?我不知道:日志中的任何地方都看不到错误。最终我发现了 PHP 扩展 xdebug,它在
education_install
中使用时显示 < code>drupal_install_schema 失败,因为找不到例程education_course_schema
、education_course_market
和education_course_event
。那时解决方案非常明显:瞧,它成功了!
因此,我了解到,
drupal_install_schema
在失败时不会记录任何错误,只需要对drupal_install_schema
进行一次调用,并且它会安装您在数组中返回的所有模式,drupal_install_schema
值得一读,最后,xdebug 是一个非常方便的实用程序!I would like to share with you my experiences with this error on Drupal 6. In my first-ever module I had three tables. I had an entry for each in my
hook_schema
(callededucation_schema
):In my
hook_install
, I initially had the following:No tables were creating at module install. Why? I had no idea: no errors to be seen anywhere in the logs. Eventually I found out about the PHP extension xdebug, which, when used in
education_install
revealed thatdrupal_install_schema
failed because it could not find the routineseducation_course_schema
,education_course_market
andeducation_course_event
. At that point the solution was quite obvious:And voila, it worked!
So, I learned that
drupal_install_schema
does not log any error when it fails, that only one call todrupal_install_schema
is required and that it installs all schemas that you return in the array, that the API documentation ofdrupal_install_schema
is worth reading, and finally that xdebug is a very handy utility!