Set term tid programmatically I've a csv with taxonomy terms, with tids.
I've to import, with a module, these terms in a new drupal installation, but if I try to set the tid programmatically, the module does not create the term. Instead, if I don't set the tid, the term is created with but with the autoincremental tid.
This code doesn't work:

$term = new stdClass();
$term-&gt;name = 'Test';
$term-&gt;vid = 3;
$term-&gt;tid = 10; // if I remove this line the term is created
taxonomy_term_save($term);


The doc says: 
tid: (optional) The unique ID for the term being saved. If $term->tid is empty or omitted, a new term will be inserted.

Is there a way to set the tid programmatically?
Or is there a module that do this?
If you set $term-&gt;tid for a taxonomy term you save with taxonomy_term_save(), the function will take you are updating an existing taxonomy term, with the consequence that the taxonomy term is not saved.

You could change the taxonomy term ID for the taxonomy term you right saved, but there is the risk of conflict with an existing taxonomy term you didn't import. You should change more that one database  table, and you should let other modules handling data related to taxonomy terms know they need to update their data, which means you probably should make those modules think a taxonomy term is deleted, and a new taxonomy term is created.
See also the code for taxonomy_term_delete() to understand what Drupal does when a taxonomy term is deleted.

If you really need to export taxonomy terms from a site, and import them in a different Drupal site, you should be interested to the Universally Unique Identifier module. In that way, the taxonomy term exported from site A, and imported in site B will have the same UUID.
In Drupal 8, any entity defined from Drupal has a UUID. The schema definition used for taxonomy terms in Drupal 8, for example, is the following one.

  $schema['taxonomy_term_data'] = array(
    'description' =&gt; 'Stores term information.', 
    'fields' =&gt; array(
      'tid' =&gt; array(
        'type' =&gt; 'serial', 
        'unsigned' =&gt; TRUE, 
        'not null' =&gt; TRUE, 
        'description' =&gt; 'Primary Key: Unique term ID.',
      ), 
      'uuid' =&gt; array(
        'description' =&gt; 'Unique Key: Universally unique identifier for this entity.', 
        'type' =&gt; 'varchar', 
        'length' =&gt; 128, 
        'not null' =&gt; FALSE,
      ), 
      'vid' =&gt; array(
        'type' =&gt; 'int', 
        'unsigned' =&gt; TRUE, 
        'not null' =&gt; TRUE, 
        'default' =&gt; 0, 
        'description' =&gt; 'The {taxonomy_vocabulary}.vid of the vocabulary to which the term is assigned.',
      ), 
      // …
    ),
    // …
  );