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) »
  • How to import option groups using the batch import.php script
Pages: [1]

Author Topic: How to import option groups using the batch import.php script  (Read 1195 times)

SarahG (FountainTribe)

  • Ask me questions
  • ****
  • Posts: 782
  • Karma: 29
  • CiviCRM version: 4.4.7
  • CMS version: Drupal 6, Drupal 7
  • MySQL version: 5.5
  • PHP version: 5.3
How to import option groups using the batch import.php script
May 16, 2010, 09:33:59 pm
I am using the script at:/civicrm/bin/migrate/import.php 

It chokes on this portion of my input xml file:
<OptionValue>
      <label>Cohen</label>
      <value>Cohen</value>
      <name>Cohen</name>
      <is_default>0</is_default>
      <weight>3</weight>
      <is_optgroup>0</is_optgroup>
      <is_reserved>0</is_reserved>
      <is_active>1</is_active>
      <option_group_name>tribe_20100516214054</option_group_name>
    </OptionValue>
    <OptionValue>
      <label>Israelite</label>
      <value>Israelite</value>
      <name>Israelite</name>
      <is_default>0</is_default>
      <weight>1</weight>
      <is_optgroup>0</is_optgroup>
      <is_reserved>0</is_reserved>
      <is_active>1</is_active>
      <option_group_name>tribe_20100516214054</option_group_name>
    </OptionValue>
    <OptionValue>
      <label>Levi</label>
      <value>Levi</value>
      <name>Levi</name>
      <is_default>0</is_default>
      <weight>2</weight>
      <is_optgroup>0</is_optgroup>
      <is_reserved>0</is_reserved>
      <is_active>1</is_active>
      <option_group_name>tribe_20100516214054</option_group_name>
    </OptionValue>


It seems to have an issue with ANY option group, such as additional individual prefixes.  I have debugging turned on and see the following message in the browser:


backTrace

/home2/pogernet/public_html/pogstone_demo/administrator/components/com_civicrm/civicrm/CRM/Core/Error.php, backtrace, 147
, handle,
/home2/pogernet/public_html/pogstone_demo/administrator/components/com_civicrm/civicrm/packages/PEAR.php, call_user_func, 931
/home2/pogernet/public_html/pogstone_demo/administrator/components/com_civicrm/civicrm/packages/DB.php, PEAR_Error, 966
/home2/pogernet/public_html/pogstone_demo/administrator/components/com_civicrm/civicrm/packages/PEAR.php, DB_Error, 564
/home2/pogernet/public_html/pogstone_demo/administrator/components/com_civicrm/civicrm/packages/DB/common.php, raiseError, 1903
/home2/pogernet/public_html/pogstone_demo/administrator/components/com_civicrm/civicrm/packages/DB/mysql.php, raiseError, 898
/home2/pogernet/public_html/pogstone_demo/administrator/components/com_civicrm/civicrm/packages/DB/mysql.php, mysqlRaiseError, 327
/home2/pogernet/public_html/pogstone_demo/administrator/components/com_civicrm/civicrm/packages/DB/common.php, simpleQuery, 1216
/home2/pogernet/public_html/pogstone_demo/administrator/components/com_civicrm/civicrm/packages/DB/DataObject.php, query, 2411
/home2/pogernet/public_html/pogstone_demo/administrator/components/com_civicrm/civicrm/packages/DB/DataObject.php, _query, 1043
/home2/pogernet/public_html/pogstone_demo/administrator/components/com_civicrm/civicrm/CRM/Core/DAO.php, insert, 280
/home2/pogernet/public_html/pogstone_demo/administrator/components/com_civicrm/civicrm/bin/migrate/import.php, save, 126
/home2/pogernet/public_html/pogstone_demo/administrator/components/com_civicrm/civicrm/bin/migrate/import.php, optionValues, 57
/home2/pogernet/public_html/pogstone_demo/administrator/components/com_civicrm/civicrm/bin/migrate/import.php, run, 357
/home2/pogernet/public_html/pogstone_demo/administrator/components/com_civicrm/civicrm/bin/migrate/import.php, run, 365

unrecoverable error
    Sorry. A non-recoverable error has occurred.

    DB Error: constraint violation

    Return to home page.

Error Details:

Array
(
    [callback] => Array
        (
           
  • => CRM_Core_Error
  • [1] => handle
            )

       
Code: [Select]
=> -3
    [message] => DB Error: constraint violation
    [mode] => 16
    [debug_info] => INSERT INTO civicrm_option_value (label , value , name , is_default , weight , is_optgroup , is_reserved , is_active ) VALUES ('Cohen' , 'Cohen' , 'Cohen' ,  0 ,  3 ,  0 ,  0 ,  1 )  [nativecode=1452 ** Cannot add or update a child row: a foreign key constraint fails (`pogernet_jml04`.`civicrm_option_value`, CONSTRAINT `FK_civicrm_option_value_option_group_id` FOREIGN KEY (`option_group_id`) REFERENCES `civicrm_option_group` (`id`) ON DELETE CASCADE)]
    [type] => DB_Error
    [user_info] => INSERT INTO civicrm_option_value (label , value , name , is_default , weight , is_optgroup , is_reserved , is_active ) VALUES ('Cohen' , 'Cohen' , 'Cohen' ,  0 ,  3 ,  0 ,  0 ,  1 )  [nativecode=1452 ** Cannot add or update a child row: a foreign key constraint fails (`pogernet_jml04`.`civicrm_option_value`, CONSTRAINT `FK_civicrm_option_value_option_group_id` FOREIGN KEY (`option_group_id`) REFERENCES `civicrm_option_group` (`id`) ON DELETE CASCADE)]
    [to_string] => [db_error: message="DB Error: constraint violation" code=-3 mode=callback callback=CRM_Core_Error::handle prefix="" info="INSERT INTO civicrm_option_value (label , value , name , is_default , weight , is_optgroup , is_reserved , is_active ) VALUES ('Cohen' , 'Cohen' , 'Cohen' ,  0 ,  3 ,  0 ,  0 ,  1 )  [nativecode=1452 ** Cannot add or update a child row: a foreign key constraint fails (`pogernet_jml04`.`civicrm_option_value`, CONSTRAINT `FK_civicrm_option_value_option_group_id` FOREIGN KEY (`option_group_id`) REFERENCES `civicrm_option_group` (`id`) ON DELETE CASCADE)]"]
)

Did I help you? Please donate to the Civi-Make-It-Happen campaign  CiviCRM for mobile devices! 

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: How to import option groups using the batch import.php script
May 16, 2010, 09:38:48 pm

seems like you are missing the option group definition

check:

http://svn.civicrm.org/sfschool/trunk/sql/xml/SFSModuleData.xml

search for OptionGroups

how are you generating that xml file?

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

SarahG (FountainTribe)

  • Ask me questions
  • ****
  • Posts: 782
  • Karma: 29
  • CiviCRM version: 4.4.7
  • CMS version: Drupal 6, Drupal 7
  • MySQL version: 5.5
  • PHP version: 5.3
Re: How to import option groups using the batch import.php script
May 29, 2010, 06:38:26 pm
I generated a new xml file using the script at "/public_html/www2/sites/all/modules/civicrm/bin/migrate/export.php"    This produced an xml file that I was able to import on another site.   However, it only exported the custom data setups.  It did not export any custom relationship types, custom activity types, custom event types, or custom individual prefixes.

What steps am I missing?
Did I help you? Please donate to the Civi-Make-It-Happen campaign  CiviCRM for mobile devices! 

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: How to import option groups using the batch import.php script
May 30, 2010, 07:00:42 am

you will need to extend the code to do so. I've added a few more fields in 3.2. I did not need some of those types for my needs and hence did not include them

please submit your changes if you do extend the code

thanx

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

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • How to import option groups using the batch import.php script

This forum was archived on 2017-11-26.