Drupal - After deleting all nodes, how do I reset the node ID to start from 1 again?

ALTER TABLE `node` AUTO_INCREMENT = 1;

P.S - Others who have replied on this question: I just did a small check after deleting content and the associated content is indeed deleted, node_revisions and field_* tables are empty. node_delete says the same - http://api.drupal.org/api/drupal/modules--node--node.module/function/node_delete_multiple/7

Sometimes on migrations projects when you migrate from other platforms (ex. ASP + MSSQL), sometimes it becomes unavoidable to reset the nid due to lot of factors. I am sure it could be avoided but time/code tradeoff is always there.


Plase don't truncate the node table just like that, there are some other tables connected to the node table, like node_revisions, sequences, fields tables, taxonomy tables, and many more.

There is no secure way to do this, it really depends on your site, you'll have to truncate and adjust all tables that have an nid including the sequences table. Remember, it is highly probable that your site become unusable, so don't start without a backup first.


You can use the module Delete all with the following drush commands:

Drupal 7

Delete nodes of all types, and reset node, revision and comment counters.

drush delete-all --reset

Drupal 8

see here

Deletes all content of all types.

drush delete-all-delete-content

And then:

ALTER TABLE `node` AUTO_INCREMENT=1;
ALTER TABLE `node_revision` AUTO_INCREMENT=1;
ALTER TABLE `node_field_data` AUTO_INCREMENT=1;
ALTER TABLE `node_field_revision` AUTO_INCREMENT=1;

Tags:

7