Create a field instance programmatically on a taxonomy vocabulary I'm trying to create a module which creates a taxonomy vocabulary on installation of the module, and creates one text field on the taxonomy vocabulary/term. But I'm getting the following error when I enable my module:


  [error] FieldException: Attempt to create an instance of field field_flickr_photoset on forbidden entity type taxonomy_term. in field_create_instance() (line 468 of
  /var/www/www.example.com/htdocs/modules/field/field.crud.inc).


First of al, why a Forbidden entity type? Is it not possible to create a field on a taxonomy vocabulary through code? Or am I missing some parameters? 

I used very similar code to create a node type and attach fields to it, which currently works without any problems. I didn't think that changing the entity type would cause such problems.

I tried searching on google and here on how to do this, but all I get is people who are asking how to attach a taxonomy term reference field to a node type, which is not what I'm asking. It's attaching a text field to a taxonomy term/vocabulary.
If you look in taxonomy_entity_info() you'll see this code that defines the taxonomy_vocabulary entity type:

$return['taxonomy_vocabulary'] = array(
  'label' =&gt; t('Taxonomy vocabulary'),
  'controller class' =&gt; 'TaxonomyVocabularyController',
  'base table' =&gt; 'taxonomy_vocabulary',
  'entity keys' =&gt; array(
    'id' =&gt; 'vid',
    'label' =&gt; 'name',
  ),
  'fieldable' =&gt; FALSE,
);


The important bit to note is 'fieldable' =&gt; FALSE...that's why it's 'forbidden' to add fields to that type.

The taxonomy_term entity type is fieldable so you won't have any problem adding field instances to one of those.

If you really want to add a field to the vocabulary, you'll need to implement hook_entity_info_alter() to change the vocabulary entity to 'fieldable' =&gt; TRUE (I've done it before, it's perfectly safe):

function MYMODULE_entity_info_alter(&amp;$info) {
  $info['taxonomy_vocabulary']['fieldable'] = TRUE;
}