Drupal 7 + Services : Error 500 on user registration (Integrity constraint violation: 1048 Column 'uid' cannot be null) I'm still working on user registration with Drupal 7 and Services 3 and I got a weird Error 500 : 


  Integrity constraint violation: 1048 Column 'uid' cannot be null


Here is the code I'm using :

// REST Server URL for auth
$request_url = SERVER_URL . 'rest/user/register';

// User data
$user_data = array(
  'name' =&gt; 'newuser',
  'mail' =&gt; 'newmail@mail.com',
  'pass' =&gt; 'newpass',
  'field_city' =&gt; array('und' =&gt; array('0' =&gt; array('value' =&gt; 'NA'))),
);

$user_data = json_encode($user_data);
// cURL
$curl = curl_init($request_url);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Accept: application/json', 'Content-Type: application/json'));
curl_setopt($curl, CURLOPT_POST, TRUE);
curl_setopt($curl, CURLOPT_POSTFIELDS, $user_data);
curl_setopt($curl, CURLOPT_HEADER, TRUE);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl, CURLOPT_VERBOSE, true);

$response = curl_exec($curl);

$http_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
  if ($http_code == 200) {
  return json_decode($response);
}
else {
  $http_message = curl_error($curl);
  return $http_message;
}


Is there something I'm doing wrong ?
I think that on the other side of your code you are trying to save the user. So, to create a new user using user_save() function you have to left the first parameter blank so a new user is created. Also, add the parameter true to your json_decode($response, true) to obtain an array rather than an object.

$account = user_save('', $fields);