I have loaded thousand of nodes in different tests. How can I safely delete all the extra nodes and obly the database table to increment the node nid after the next valid (not deleted) nid? I.e., now I have 50 valid nodes, and the index starts at 250.000. How can I force it to start at nid = 51 without making the whole database crash ?

A secure way, please. Not low level, but with a module or something that respects referential integrity of the whole database.

  • while this may work, it doesn't seem like it's worth the risk. you can have 10 BILLION nodes before this is a problem.
    – user5482
    Oct 19, 2015 at 17:52
  • You're only going to find low-level solutions to this, it's a low-level problem. For better or worse, there's no mechanism in Drupal to describe relationships between tables, apart from being able to declare foreign keys in hook_schema() for documentation purposes. The vast majority of contrib modules don't use that key, so even if you were to use it you'd only cover core modules. Drupal's too loose to be able to script this sort of thing in any generic way, there needs to be a large amount of manual intervention by someone who knows the database layout well. Sucks, but it's true
    – Clive
    Oct 21, 2015 at 7:53

1 Answer 1


The node id is the primary key of the {node} database table. You need to reset the "auto_increment" property of that table to 1 (or 51 in your case). You can do that with PHPMyAdmin, or other MySQL client.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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