Drupal 7更改字段类型后未正确保存数据

问题描述 投票:0回答:1

我在客户端有一个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);

数据库已更新,但是当我保存带有诸如'8sf635'的promotion_id的实体时,它只会将8保存到数据库中。同样,当我用'qsfd7aer'保存实体时,它将在数据库中保存0。

有人可以告诉我这怎么可能吗?

检查实体的保存代码时,它看起来像:

entity_save(self::ENTITY_NAME_PROPOSITION_PROMOTION, $promotion);

并且在$ promotion对象中,promotion_id仍然是完整的字符串。

似乎表的架构未更新。运行drupal_get_schema('dpp_bab_promotion',true)时,该字段显示为int类型。

drupal drupal-7
1个回答
0
投票

有两个可能的原因。首先是您没有清除缓存,以便新架构可以生效。您说您清除了缓存,所以第二个可能性更大是您没有将更改添加到架构,而是仅更新了数据库。听起来架构仍然认为它是一个int。

© www.soinside.com 2019 - 2024. All rights reserved.