I am creating a simple node in some module code. Here is the code, the identical logic of which I have used many times:
$sub = new Node();
$sub->type = 'subscriber';
$sub->title = $email;
node_object_prepare($sub);
$sub->uid = $user->uid;
$sub->language = LANGUAGE_NONE;
$sub->status = 1;
$sub->comment = 0;
$sub->promoted = 0;
$sub->sticky = 0;
$sub->created = time();
$sub = node_submit($sub);
node_save($sub);
On the node_save() call I am getting this error:
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'last_comment_uid' cannot be null
I have explicitly turned off comments. Am I missing something new that I need to do in order to prevent this error? Any help greatly appreciated.
If your intention was for $user to be the logged in user, you need to use the statement
global $user;
before your code. Check your code to see if you forgot this?