CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Core CiviCRM Functions (Moderator: Yashodha Chaku) »
  • DB Error: constraint violation when generating PDF Letter
Pages: [1]

Author Topic: DB Error: constraint violation when generating PDF Letter  (Read 1349 times)

dowd

  • I’m new here
  • *
  • Posts: 21
  • Karma: 0
DB Error: constraint violation when generating PDF Letter
November 04, 2011, 04:29:05 am
Hi,

When I try to generate a PDF Letter I get a non recoverable error saying DB Error: constraint violation with the following backtrace

/var/www/drupal7/sites/all/modules/civicrm/CRM/Core/Error.php, backtrace, 159
, handle,
/var/www/drupal7/sites/all/modules/civicrm/packages/PEAR.php, call_user_func, 931
/var/www/drupal7/sites/all/modules/civicrm/packages/DB.php, PEAR_Error, 968
/var/www/drupal7/sites/all/modules/civicrm/packages/PEAR.php, DB_Error, 564
/var/www/drupal7/sites/all/modules/civicrm/packages/DB/common.php, raiseError, 1903
/var/www/drupal7/sites/all/modules/civicrm/packages/DB/mysql.php, raiseError, 898
/var/www/drupal7/sites/all/modules/civicrm/packages/DB/mysql.php, mysqlRaiseError, 327
/var/www/drupal7/sites/all/modules/civicrm/packages/DB/common.php, simpleQuery, 1216
/var/www/drupal7/sites/all/modules/civicrm/packages/DB/DataObject.php, query, 2424
/var/www/drupal7/sites/all/modules/civicrm/packages/DB/DataObject.php, _query, 1054
/var/www/drupal7/sites/all/modules/civicrm/CRM/Core/DAO.php, insert, 288
/var/www/drupal7/sites/all/modules/civicrm/CRM/Activity/BAO/Activity.php, save, 286
/var/www/drupal7/sites/all/modules/civicrm/CRM/Contact/Form/Task/PDFLetterCommon.php, createActivityTarget, 318
/var/www/drupal7/sites/all/modules/civicrm/CRM/Contact/Form/Task/PDF.php, postProcess, 122
/var/www/drupal7/sites/all/modules/civicrm/CRM/Core/Form.php, postProcess, 250
/var/www/drupal7/sites/all/modules/civicrm/CRM/Core/StateMachine.php, mainProcess, 167
/var/www/drupal7/sites/all/modules/civicrm/CRM/Core/QuickForm/Action/Next.php, perform, 64
/var/www/drupal7/sites/all/modules/civicrm/packages/HTML/QuickForm/Controller.php, perform, 203
/var/www/drupal7/sites/all/modules/civicrm/packages/HTML/QuickForm/Page.php, handle, 103
/var/www/drupal7/sites/all/modules/civicrm/CRM/Core/Controller.php, handle, 284
/var/www/drupal7/sites/all/modules/civicrm/CRM/Core/Invoke.php, run, 224
/var/www/drupal7/sites/all/modules/civicrm/drupal/civicrm.module, invoke, 447
, civicrm_invoke,
/var/www/drupal7/includes/menu.inc, call_user_func_array, 503
/var/www/drupal7/index.php, menu_execute_active_handler, 21

Am using Civi 4.0.7 on Drupal 7.8

Any ideas of a possible cause?

Dowd

Hershel

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4640
  • Karma: 176
    • CiviHosting
  • CiviCRM version: Latest
  • CMS version: Mostly WordPress and Drupal
Re: DB Error: constraint violation when generating PDF Letter
November 06, 2011, 05:30:25 am
Are there more details regarding the constraint violation ?
CiviHosting and CiviOnline -- The CiviCRM hosting experts, since 2007

See here for the official: What to do if you think you've found a bug.

dowd

  • I’m new here
  • *
  • Posts: 21
  • Karma: 0
Re: DB Error: constraint violation when generating PDF Letter
November 07, 2011, 07:48:42 am
Hi,
That is all the details that are displayed I'm afraid.

Hershel

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4640
  • Karma: 176
    • CiviHosting
  • CiviCRM version: Latest
  • CMS version: Mostly WordPress and Drupal
Re: DB Error: constraint violation when generating PDF Letter
November 07, 2011, 07:50:59 am
Hmmm. Do any PDF letters work?

Can you do View Source on your error page and post the full text? You may need to post it as an attachment.
CiviHosting and CiviOnline -- The CiviCRM hosting experts, since 2007

See here for the official: What to do if you think you've found a bug.

LindseyM

  • I post frequently
  • ***
  • Posts: 229
  • Karma: 8
  • CiviCRM version: 4.4.6
  • CMS version: Drupal 7
  • MySQL version: 5.5
  • PHP version: 5.3.6
Re: DB Error: constraint violation when generating PDF Letter
November 23, 2011, 02:58:54 pm
I work with dowd so thought I'd update.  It looks at present like I can generate a pdf letter to one individual if I am in their record and choose to generate the pdf as an action from there.  If I choose several individuals from a search and action pdf I get the backtrace mentioned.  I have attached the source view of the backtrace for you to look at further.  Thanks.

Hershel

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4640
  • Karma: 176
    • CiviHosting
  • CiviCRM version: Latest
  • CMS version: Mostly WordPress and Drupal
Re: DB Error: constraint violation when generating PDF Letter
November 23, 2011, 05:01:25 pm
Seems the reference to the activity type is failing. Did you delete any activity types?
CiviHosting and CiviOnline -- The CiviCRM hosting experts, since 2007

See here for the official: What to do if you think you've found a bug.

LindseyM

  • I post frequently
  • ***
  • Posts: 229
  • Karma: 8
  • CiviCRM version: 4.4.6
  • CMS version: Drupal 7
  • MySQL version: 5.5
  • PHP version: 5.3.6
Re: DB Error: constraint violation when generating PDF Letter
November 24, 2011, 08:02:08 am
Not that I am aware of.  Would that show in Option Lists-Activity Types or somewhere else?  All looks well in there, but might we have inadvertently deleted an activity type some other way?

Hershel

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4640
  • Karma: 176
    • CiviHosting
  • CiviCRM version: Latest
  • CMS version: Mostly WordPress and Drupal
Re: DB Error: constraint violation when generating PDF Letter
November 24, 2011, 08:04:41 am
Can you run this SQL in phpMyAdmin and post the results?

Code: [Select]
SELECT label,`value`,`name` FROM civicrm_option_value
WHERE option_group_id=2
ORDER BY `value`
CiviHosting and CiviOnline -- The CiviCRM hosting experts, since 2007

See here for the official: What to do if you think you've found a bug.

jcasharpe

  • I post occasionally
  • **
  • Posts: 57
  • Karma: 5
    • Woodlands Church
  • CiviCRM version: 4.4.6
  • CMS version: Drupal 7
  • MySQL version: MariaDB 10.0.13
  • PHP version: 5.5
Re: DB Error: constraint violation when generating PDF Letter
November 24, 2011, 11:11:36 am
Here's the output:

Quote
+-----------------------------+-------+-----------------------------+
| label                       | value | name                        |
+-----------------------------+-------+-----------------------------+
| Meeting                     | 1     | Meeting                     |
| Pledge Acknowledgment       | 10    | Pledge Acknowledgment       |
| Pledge Reminder             | 11    | Pledge Reminder             |
| Inbound Email               | 12    | Inbound Email               |
| Open Case                   | 13    | Open Case                   |
| Follow up                   | 14    | Follow up                   |
| Change Case Type            | 15    | Change Case Type            |
| Change Case Status          | 16    | Change Case Status          |
| Membership Renewal Reminder | 17    | Membership Renewal Reminder |
| Change Case Start Date      | 18    | Change Case Start Date      |
| Bulk Email                  | 19    | Bulk Email                  |
| Phone Call                  | 2     | Phone Call                  |
| Assign Case Role            | 20    | Assign Case Role            |
| Remove Case Role            | 21    | Remove Case Role            |
| Print PDF Letter            | 22    | Print PDF Letter            |
| Merge Case                  | 23    | Merge Case                  |
| Reassigned Case             | 24    | Reassigned Case             |
| Link Cases                  | 25    | Link Cases                  |
| Change Case Tags            | 26    | Change Case Tags            |
| Survey                      | 27    | Survey                      |
| Canvass                     | 28    | Canvass                     |
| PhoneBank                   | 29    | PhoneBank                   |
| Email                       | 3     | Email                       |
| WalkList                    | 30    | WalkList                    |
| Petition                    | 31    | Petition                    |
| Reminder Sent               | 32    | Reminder Sent               |
| Make Contact                | 33    | Make Contact                |
| Alpha Course                | 34    | Alpha Course                |
| Direct Action               | 35    | Direct Action               |
| Door Knock                  | 36    | Door Knock                  |
| Letter of Inquiry           | 37    | Letter of Inquiry           |
| Press Release               | 38    | Press Release               |
| Proposal                    | 39    | Proposal                    |
| Text Message (SMS)          | 4     | SMS                         |
| Report                      | 40    | Report                      |
| Volunteer Time              | 41    | Volunteer Time              |
| Media Coverage              | 42    | Media Coverage              |
| Event Registration          | 5     | Event Registration          |
| Contribution                | 6     | Contribution                |
| Membership Signup           | 7     | Membership Signup           |
| Membership Renewal          | 8     | Membership Renewal          |
| Tell a Friend               | 9     | Tell a Friend               |
| Add Client To Case          | 9     | Add Client To Case          |
+-----------------------------+-------+-----------------------------+
43 rows in set (0.00 sec)

I'm guessing its the duplicate value for 9 thats the problem?

Hershel

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4640
  • Karma: 176
    • CiviHosting
  • CiviCRM version: Latest
  • CMS version: Mostly WordPress and Drupal
Re: DB Error: constraint violation when generating PDF Letter
November 25, 2011, 01:57:27 am
> I'm guessing its the duplicate value for 9 thats the problem?

No, not at all. I, however, misread your error. The error is:

Code: [Select]
INSERT INTO civicrm_activity_target (activity_id ,
target_contact_id ) VALUES ( 24 , 2 ) [nativecode=1452 ** Cannot add or
update a child row: a foreign key constraint fails
(`woodlands_civicrm4`.`civicrm_activity_target`, CONSTRAINT
`FK_civicrm_activity_target_activity_id` FOREIGN KEY (`activity_id`)
REFERENCES `civicrm_activity` (`id`) ON DELETE CASCADE)]

The actual error is thus that it's trying to assign activity_id the value 24, but no such activity exists with that id.

It's odd--I don't know why it fails. Can you try the same operation on the demo?
CiviHosting and CiviOnline -- The CiviCRM hosting experts, since 2007

See here for the official: What to do if you think you've found a bug.

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: DB Error: constraint violation when generating PDF Letter
November 25, 2011, 11:13:23 am

your best bet might be to add some debug statements based on backtrace and see how/where/why we are getting id 24 from

this place might be a good place to start:

/var/www/drupal7/sites/all/modules/civicrm/CRM/Activity/BAO/Activity.php, save, 286
/var/www/drupal7/sites/all/modules/civicrm/CRM/Contact/Form/Task/PDFLetterCommon.php, createActivityTarget, 318

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

gastrit

  • I post occasionally
  • **
  • Posts: 60
  • Karma: 2
  • CiviCRM version: 4.2.2
  • CMS version: 7.8
  • MySQL version: 5.1.41
  • PHP version: 5.3.2
Re: DB Error: constraint violation when generating PDF Letter
March 15, 2012, 08:49:56 am
I had the same problem and for me it tried to create a record in civicrm_activity_target with activity_id = 1. When I debugged the file CRM/Contact/Form/Task/PDFLetterCommon.php I noticed that the form was somewhere assigned activityId=1 and there is a if clause on line 303 thats uses the forms activity id if it exists. I simply added to the if condition that activityId also has to be greater than 1 and therefore it was not used when creating a new activity on line 312.

Why do we ever want to say which id a new activity should have. Don't we have auto inc's that decide that?

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Core CiviCRM Functions (Moderator: Yashodha Chaku) »
  • DB Error: constraint violation when generating PDF Letter

This forum was archived on 2017-11-26.