Resetting the Initial NID to 1 After Deleting All Nodes in Drupal 8

 

Writing this mostly as a note to myself.

I'm in the process of migrating nodes from three different Drupal sites into a new Drupal 8 site.  Over the last day or so, I've been working on building out the Migration YML (Migration API FTW).  Of course as I've been debugging I've been importing and rolling back migrations.  Of course, as I do this, my starting NID is getting larger and larger.  It was over after me test data nigrations.  When the time comes for the final import of content, I want the first NID to be 1 (just for cleanliness sake).

In Drupal 7 the delete all module did this with a "--reset" flag but doesn't in D8.  Here's the couple of lines of SQL code to reset the auto increment on the necessary tables:

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;

Make sure you DELETE all nodes before doing this, otherwise you are likely to cause data corruption down the line,

Share and Enjoy!