【发布时间】:2020-11-16 17:15:57
【问题描述】:
我有 Drupal 8.9.8 。
我创建了一个自定义实体“corso”,其基本字段名称为varchar (50)
现在我希望该名称是 varchar(255),所以我创建了一个挂钩以在 mymodule.install 中进行更新
function mymodule_update_80485() {
$database = \Drupal::database();
$database->query("ALTER TABLE corso_field_data MODIFY name VARCHAR(300)");
$database->query("ALTER TABLE corso_field_revision MODIFY name VARCHAR(300)");
$storage_key = 'ente.field_schema_data.name';
$storage_schema = \Drupal::keyValue('entity.storage_schema.sql');
$field_schema = $storage_schema->get($storage_key);
$field_schema['ente_field_data']['fields']['name']['length'] = 300;
$field_schema['ente_field_revision']['fields']['name']['length'] = 300;
$storage_schema->set($storage_key, $field_schema);
}
我更新实体定义
$fields['name'] = BaseFieldDefinition::create('string')
->setLabel(t('Name'))
->setDescription(t('The name of the Corso entity.'))
->setRevisionable(TRUE)
->setSettings([
'max_length' => 300,
'text_processing' => 0,
])
->setDefaultValue('')
->setDisplayOptions('view', [
'label' => 'above',
'type' => 'string',
'weight' => -4,
])
->setDisplayOptions('form', [
'type' => 'string_textfield',
'weight' => -4,
])
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE)
->setRequired(TRUE);
数据库列已更新,但我仍然在 drupal 中收到“不匹配的实体和/或字段定义”
我错过了什么?
【问题讨论】:
标签: database drupal entity drupal-8