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) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • MySQL error when using TAGGING API
Pages: [1]

Author Topic: MySQL error when using TAGGING API  (Read 1398 times)

CatorgHans

  • I post frequently
  • ***
  • Posts: 157
  • Karma: 5
  • CiviCRM version: 4.4
  • CMS version: drupal
MySQL error when using TAGGING API
June 07, 2010, 12:43:02 am
A drupal module I made which I have used lots of times now gives an awkward error.
In the module I am using civicrm_tag_create and shortly later civicrm_entity_tag_add:

DB Error: constraint violation

Database Error Code: Cannot add or update a child row: a foreign key constraint fails (`xxxx_crm/civicrm_entity_tag`, CONSTRAINT `FK_civicrm_entity_tag_tag_id` FOREIGN KEY (`tag_id`) REFERENCES `r1soft_saved_database_QoAawl`.`civicrm_tag` (`id`) ON DELETE CASCADE), 1452

It happens during the following SQL statement:
INSERT INTO civicrm_entity_tag (contact_id , tag_id ) VALUES ( 10248 ,  1284 )

The "Normal" tables are not responsible for the foreign key constraint problem, because both values exist in the corresponding tables.
In civicrm_entity this contact_id exists and in civicrm_tag this tag_id.

What I do not understand is the role of the table `r1soft_saved_database_QoAawl`.`civicrm_tag`. If I select that one there is no "id":1284. That is probably the cause, but what is the role if this table in maintaining foreign keys? And what can I do to solve it?

Kurund Jalmi

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4169
  • Karma: 128
    • CiviCRM
  • CiviCRM version: 4.x, future
  • CMS version: Drupal 7, Joomla 3.x
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: MySQL error when using TAGGING API
June 07, 2010, 01:20:44 am
Quote
What I do not understand is the role of the table `r1soft_saved_database_QoAawl`.`civicrm_tag`. If I select that one there is no "id":1284. That is probably the cause, but what is the role if this table in maintaining foreign keys? And what can I do to solve it?
How do you select id = 1284 ?
Why don't you check if tag is created before calling civicrm_entity_tag_add.

HTh
Kurund
Found this reply helpful? Support CiviCRM

CatorgHans

  • I post frequently
  • ***
  • Posts: 157
  • Karma: 5
  • CiviCRM version: 4.4
  • CMS version: drupal
Re: MySQL error when using TAGGING API
June 07, 2010, 01:27:42 am
I checked it with mysql command on the server:
select * from `r1soft_saved_database_QoAawl`.`civicrm_tag` where id > 1270;

I cannot do it in the code, because I have no idea why MySQL has created this database:
`r1soft_saved_database_QoAawl`

And why it is part of the constraint check of my normal database?

Kurund Jalmi

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4169
  • Karma: 128
    • CiviCRM
  • CiviCRM version: 4.x, future
  • CMS version: Drupal 7, Joomla 3.x
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: MySQL error when using TAGGING API
June 07, 2010, 01:33:05 am
civicrm_tag_create api's returns the tag object if it is created.

Kurund
Found this reply helpful? Support CiviCRM

CatorgHans

  • I post frequently
  • ***
  • Posts: 157
  • Karma: 5
  • CiviCRM version: 4.4
  • CMS version: drupal
Re: MySQL error when using TAGGING API
June 07, 2010, 01:41:01 am
Thanks.

The problem is not that a table in my normal database has the wrong value.
But that somehow the constraint check is not checking my normal database, but a table in the database called "r1soft_saved_database_QoAawl".

It might have to do with the restoring of a backup. That somehow the constraint check is done on a "backup database" in stead of the normal database.

Kurund Jalmi

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4169
  • Karma: 128
    • CiviCRM
  • CiviCRM version: 4.x, future
  • CMS version: Drupal 7, Joomla 3.x
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: MySQL error when using TAGGING API
June 07, 2010, 01:43:38 am
You can double check your civicrm.settings.php and make sire it has correct db name etc.

Kurund
Found this reply helpful? Support CiviCRM

CatorgHans

  • I post frequently
  • ***
  • Posts: 157
  • Karma: 5
  • CiviCRM version: 4.4
  • CMS version: drupal
Re: MySQL error when using TAGGING API
June 07, 2010, 02:05:11 am
Those settings are correct.
A db restore went corrupt. All Constraints seem wrong now. They all point to wrong database. Here are the first 3:
  CONSTRAINT `FK_civicrm_acl_cache_contact_id` FOREIGN KEY (`contact_id`) REFERENCES `r1soft_saved_database_QoAawl`.`civicrm_contact` (`id`) ON DELETE CASCADE
  CONSTRAINT `FK_civicrm_acl_contact_cache_contact_id` FOREIGN KEY (`contact_id`) REFERENCES `r1soft_saved_database_QoAawl`.`civicrm_contact` (`id`) ON DELETE CASCADE,
  CONSTRAINT `FK_civicrm_acl_contact_cache_user_id` FOREIGN KEY (`user_id`) REFERENCES `r1soft_saved_database_QoAawl`.`civicrm_contact` (`id`) ON DELETE CASCADE

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • MySQL error when using TAGGING API

This forum was archived on 2017-11-26.