On our system (D5) two nodes have been deleted (by mistake). I need them back but I can't simply load a backup as there's a lot of new content created. I want to create these two new nodes again, manually, and they will obviously have a bigger nid.

Then, I would like to simply change the nid to the old (the deleted one) nid. This way, all node references will work again. (Node references from other content types).

I tried the following:

//load the newly created node
$node_new = node_load(1234580);

//put the
$node_new->nid = 81580; //this is the nid of the deleted node
$node_new->vid = 81580; //and its vid 


And if I print_r $node_new at the end, it says the nid is 81580, but on the database there's no node with that nide.

How can I create a node and specify the nid manually??

  • Drupal 5.x End of Life Announcement drupal.org/node/1027214
    – niksmac
    May 7 '12 at 9:33
  • Yes, but maybe somebody can let me know what I'm doing wrong. I think I might have the same issue with Drupal 6 (1.delete one node. 2.create a new node. 3. edit that new node, put the old NID and save it).
    – Ferran Gil
    May 7 '12 at 9:42

You'll need to change the nid manually in the database. As far as I know, only the D7 node_save() allows you to specify the nid during initial save (because it allows you to set $node->is_new as well instead of overriding it).

And no version will ever allow you to change the nid in an update.

  • 1
    All right. Manually updating nids on the database was the last option but I'm going to do it now. I found a similar issue drupal.org/node/1196952.
    – Ferran Gil
    May 7 '12 at 10:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.