【发布时间】:2020-01-09 09:18:45
【问题描述】:
我在客户端有一个 Drupal 7 应用程序。使用带有以下代码的安装文件(在 *.install 文件中)将数据库中的字段从 int 更改为 varchar(255) 后:
$spec = array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'description' => t('The ID of the promotion, found in')
);
db_change_field('promotion', 'promotion_id', 'promotion_id', $spec);
数据库已更新,但是当我保存一个带有promotion_id 的实体时,例如'8sf635',它只会将8 保存到数据库中。此外,当我使用“qsfd7aer”保存实体时,它将在数据库中保存 0。
谁能告诉我这是怎么发生的?
当检查实体的保存代码时,它看起来像:
entity_save(self::ENTITY_NAME_PROPOSITION_PROMOTION, $promotion);
并且在 $promotion 对象中,promotion_id 仍然是完整的字符串。
表的架构似乎没有更新。 运行 drupal_get_schema('dpp_bab_promotion', true) 时,它将字段显示为 int 类型。
【问题讨论】:
-
您必须将架构更改为 .intall 文件,使用 api.drupal.org/hook_schema_alter 之类的钩子并清除注册表和实体缓存您可以在此处查看 db_change_field 的使用情况api.drupal.org/api/drupal/includes!database!database.inc/…
-
第一个 sn-p 来自 .install 文件。我使用 drush 清除了寄存器和所有缓存,但没有工作。这还有其他原因吗?数据库更改已完成,所有外键也已创建。
-
您能否验证数据库中的字段类型是否确实发生了变化?
-
数据库中的字段类型发生了变化。 Drupal 中的架构未更新。