I recently had to migrate data into Drupal. To do this I decided to just run drupal_execute(), to create the nodes. I ran into a few quirks and thought I would share my trials with the world.

My first issue was, How do I get the new node id that was created by drupal_execute(). Well It was easier than I thought. I did a little goggling and found people saying that you should use db_last_id(), well that did not work for me. Instead I used the “$form_state” variable that I passed into the drupal_execute function. I noticed that after running drupal_execute() I could use $form_state['nid'] to retrieve the nodes id. Wow wasn’t that easy.

The nodes I was creating were using cck fields. I noticed that only the first node’s cck fields were created correctly. All subsequent nodes were created with cck fields containing just 1 character(I believe this only happened on select fields). To fix this issue I had to use the node id that I retireved and set the cck fields again. Then do a node_save(). Now all my fields are correct and I can go Fishing.:)