I get this error while i am trying to mass subscribe users/email for a newsletter using the simplenews module in D7. How can i solve this error ?

PDOException: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 
'tid' cannot be null: INSERT INTO {simplenews_subscription} 
(tid, snid, status, timestamp, source) VALUES 
(:db_insert_placeholder_0, :db_insert_placeholder_1, 
:db_insert_placeholder_3, :db_insert_placeholder_4); 
Array ( [:db_insert_placeholder_0] => 
[:db_insert_placeholder_1] => 1285 
[:db_insert_placeholder_2] => 1 
[:db_insert_placeholder_3] => 1368003712 
[:db_insert_placeholder_4] => ) 
in simplenews_subscription_save() 
(line 1501 of /sites/all/modules/simplenews/simplenews.module).

You are getting this error because when it is trying to insert the taxonomy term ID:

INSERT INTO {simplenews_subscription} (tid ...

The value that is being passed is null:

Array ( [:db_insert_placeholder_0] => 

Best plan to fix this is to try and determine why it is not passing this taxonomy term. Did you select the term as an option when mass subscribing? This may be a bug or quirk in simplenews itself according to this thread or maybe an issue with corruption of your dataset.

Another way to resolve this if that is the case would be to alter that column to allow nulls (temporarily!), do your mass subscription action, manually add the correct taxonomy term to the database and then finish by restoring the null constraint to the column.

  • i changed this line in the simplenews_realname.module file - before - $checked_newsletters = array_filter($form_state['values']['newsletters']); after - $checked_newsletters = array_keys(array_filter($form_state['values']['newsletters'])); and it worked. But it does not insert the name into the db. I searched and found that it's fault with the realname module. Is there any workaround? – Dan May 13 '13 at 10:19
  • Can you be more specific about the realname module issue? Is there an existing issue open for this on Drupal.org? We should probably modify the question or start a new one with your research to make this thread more useful. – schnippy May 13 '13 at 14:37
  • 1
    This patch drupal.org/node/1912712 solves the issue as well. – Dan May 13 '13 at 18:57
  • ah - nice work! does that solve your issue? you should definitely cross-post back to that drupal.org issue with your finding and mark the patch RTBC to get this queued for the next release. – schnippy May 13 '13 at 19:44
  • Yes it solves my issue of the mass subscribe. But has some minor side issues as well such as- 1.When i go to the Newsletter Subscriptions page and i hit next at the bottom of the page for the next subscribers, it still shows me the first set. The bottom menu changes from page 1 to 2 but the display is still showing the first 30 subscribers. 2.And when i Export all subscribers then only the email ids are shown comma separated. There are no names. – Dan May 27 '13 at 9:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.