How to create nodes using node_save? I'm trying to migrate my current html site into Drupal. I have over 80,000 pages I have to migrate so I thought instead of sitting in front of a computer for 50 years I would create a module. I was able to create a script that extracts the html from each directory and now I got to a road block where I need to create a node. I'm trying to create a new node using node_save(), but when node_save is executed, I get a PDOException error with everything I try. I'm passing in $node, which is an array which is then casted into an object. 


  PDOException: in field_sql_storage_field_storage_write() (line 424 of /srv/www/htdocs/modules/field/modules/field_sql_storage/field_sql_storage.module).


This is how we are currently creating the node, but it produces an error:

$node= array(
    'uid' =&gt; $user-&gt;uid,
    'name' =&gt; $user-&gt;name,
    'type' =&gt; 'page',
    'language' =&gt; LANGUAGE_NONE,
    'title' =&gt; $html['title'],
    'status' =&gt; 1,
    'promote' =&gt; 0,
    'sticky' =&gt; 0,
    'created' =&gt; (int)REQUEST_TIME,
    'revision' =&gt; 0,
    'comment' =&gt; '1',
    'menu' =&gt; array(
        'enabled' =&gt; 0,
        'mlid' =&gt; 0,
        'module' =&gt; 'menu',
        'hidden' =&gt; 0,
        'has_children' =&gt; 0,
        'customized' =&gt; 0,
        'options' =&gt; array(),
        'expanded' =&gt; 0,
        'parent_depth_limit' =&gt; 8,
        'link_title' =&gt; '',
        'description' =&gt; '',
        'parent' =&gt; 'main-menu:0',
        'weight' =&gt; '0',
        'plid' =&gt; '0',
        'menu_name' =&gt; 'main-menu',
    ),
    'path' =&gt; array(
        'alias' =&gt; '',
        'pid' =&gt; null,
        'source' =&gt; null,
        'language' =&gt; LANGUAGE_NONE,
        'pathauto' =&gt; 1,
    ),
    'nid' =&gt; null,
    'vid' =&gt; null,
    'changed' =&gt; '',
    'additional_settings__active_tab' =&gt; 'edit-menu',
    'log' =&gt; '',
    'date' =&gt; '',
    'submit' =&gt; 'Save',
    'preview' =&gt; 'Preview',
    'private' =&gt; 0,
    'op' =&gt; 'Save',
    'body' =&gt; array(LANGUAGE_NONE =&gt; array(
        array(
            'value' =&gt; $html['html'],
            'summary' =&gt; $link,
            'format' =&gt; 'full_html',
        ),
    )),
        'validated' =&gt; true,
);

node_save((object)$node);

// Small hack to link revisions to our test user.
db_update('node_revision')
    -&gt;fields(array('uid' =&gt; $node-&gt;uid))
    -&gt;condition('vid', $node-&gt;vid)
    -&gt;execute();
Instead of casting an array into a stdClass object, you could try creating a new stdClass() object and then using node_object_prepare() to prepare the object for creating a new node and then finally manually changing the values of uid, name, title, language, body, etc. Also, be sure to use node_submit() before saving the new node to the database.

Example: http://drupal.org/node/1173136