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

 
Sean Reiser

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:

  1. ALTER TABLE `node` AUTO_INCREMENT=1;
  2. ALTER TABLE `node_revision` AUTO_INCREMENT=1;
  3. ALTER TABLE `node_field_data` AUTO_INCREMENT=1;
  4. 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!

Sean Reiser

Hi I'm Sean Reiser

#NewYorker #DrupalDeveloper #InfoSec #Photographer #GEEK #Whovian #MYSTie #LetsGoYankees #LongSufferingJetsFan #NAKnight #Quinquagenarian #CommitAwesome

I'm a 51 year old Flushing, Queens based technologist who specializes in developing, supporting and maintaining websites built in Drupal.  I am an avid photographer and all around geek.  Feel free to look at my blog, or head to my home page to learn more about me.