Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By oskar_calvo on
I have an entity call "armys", and I want to add a field to be able to choose a language.
<?php
/**
* Add language column in ddbb
*/
function armys_update_7007(&$sandbox) {
$spec = [
'type' => 'varchar',
'length' => 32,
'not null' => FALSE,
];
db_add_field('armys','language', $spec);
}
/**
* Add language field
*/
function armys_update_7008(&$sandbox) {
$field = [
'field_name' => 'language',
'type' => 'text',
'entity_types' => array('army'),
];
$field = field_create_field($field);
$instance = [
'field_name' => 'language',
'entity_type' => 'army',
'label' => 'Language',
'bundle' => 'army',
'required' => false,
];
field_create_instance($instance);
}
?>
But I get this error
Failed: FieldException: Attempt to create field name <em class="placeholder">language</em> which is reserved by entity type <em class="placeholder">comment</em>. in field_create_field() (line 93 of /home/oskar/oskar/ProjectGCMS/gcms/www/modules/field/field.crud.inc).
I want to add a language field to my entity, but I don't how to make it, any suggestion.
Thanks.
Oskar
Comments
You need to give it a
You need to give it a different field name. Try army_language or something.