Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

New install strange error in file: SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fa
 
spiralmind
Member
 
Total Posts:  39
Joined:  2010-04-13
 

Hi, Below I have tried to explain my problem in as much detail as possible in the hope someone can help me.

- Done a clean install of Magento ver 1.6

- Imported my old store data into the new database, database was carefully back-up and restored using:
http://kb.magenting.com/content/18/5/en/how-do-i-import-my-existing-magento-database-from-another-place.html

- Went through installation process

- Got this error:

Error in file: “/home/spiralmi/public_html/spiralthreads/app/code/core/Mage/Catalog/sql/catalog_setup/upgrade-1.6.0.0.1-1.6.0.0.2.php” - SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`spiralmi_ecom/eav_entity_attribute`, CONSTRAINT `FK_EAV_ENTITY_ATTRIBUTE_ATTRIBUTE_ID_EAV_ATTRIBUTE_ATTRIBUTE_ID` FOREIGN KEY (`attribute_id`) REFERENCES `eav_attribute` (`attribute_id`) ON D)

Trace:
#0 /home/spiralmi/public_html/spiralthreads/app/code/core/Mage/Core/Model/Resource/Setup.php(645): Mage::exception(’Mage_Core’, ‘Error in file: ...’)
#1 /home/spiralmi/public_html/spiralthreads/app/code/core/Mage/Core/Model/Resource/Setup.php(437): Mage_Core_Model_Resource_Setup->_modifyResourceDb(’upgrade’, ‘1.6.0.0’, ‘1.6.0.0.5’)
#2 /home/spiralmi/public_html/spiralthreads/app/code/core/Mage/Core/Model/Resource/Setup.php(320): Mage_Core_Model_Resource_Setup->_upgradeResourceDb(’1.6.0.0’, ‘1.6.0.0.5’)
#3 /home/spiralmi/public_html/spiralthreads/app/code/core/Mage/Core/Model/Resource/Setup.php(235): Mage_Core_Model_Resource_Setup->applyUpdates()
#4 /home/spiralmi/public_html/spiralthreads/app/code/core/Mage/Core/Model/App.php(408): Mage_Core_Model_Resource_Setup::applyAllUpdates()
#5 /home/spiralmi/public_html/spiralthreads/app/code/core/Mage/Core/Model/App.php(336): Mage_Core_Model_App->_initModules()
#6 /home/spiralmi/public_html/spiralthreads/app/Mage.php(640): Mage_Core_Model_App->run(Array)
#7 /home/spiralmi/public_html/spiralthreads/index.php(80): Mage::run(’’, ‘store’)
#8 {main}

I have tired using the possible solution at, which involved changing the the file /lib/Zend/Cache/Backend/File.php:

http://support.hostgator.com/articles/specialized-help/technical/magento-install-error-exception-printing-is-disabled

This did not work for me, can anyone else please point me in the right direction?

Thanks

 
Magento Community Magento Community
Magento Community
Magento Community
 
Tom Robertshaw
Guru
 
Avatar
Total Posts:  485
Joined:  2009-05-17
Bath, UK
 

You can disable foreign key checks when importing a database to avoid this error, but always remembers to re-enable afterwards.

If you use phpmyadmin there’s an option to “ignore foreign key checks”, but you can do the same thing by putting:

SET FOREIGN_KEYS_CHECK = 0;

at the start of your sql file, and then this at the end:

SET FOREIGN_KEYS_CHECK = 1;

See http://dev.mysql.com/doc/refman/5.5/en/server-system-variables.html#sysvar_foreign_key_checks for more info.

 
Magento Community Magento Community
Magento Community
Magento Community
 
spiralmind
Member
 
Total Posts:  39
Joined:  2010-04-13
 

Thanks for the fast reply. I followed the instructions on this page to create a backup with foreign key disabled and followed again to import exactly as shown but it did not give me an option to enable foreign key checks again..?

http://kb.magenting.com/content/18/5/en/how-do-i-import-my-existing-magento-database-from-another-place.html

What do you suggest I do to fix the issue? I am using phpMyAdmin

Thanks

 
Magento Community Magento Community
Magento Community
Magento Community
 
Tom Robertshaw
Guru
 
Avatar
Total Posts:  485
Joined:  2009-05-17
Bath, UK
 

Hmm, that should be the option that does it.  If you’re using that option in phpmyadmin, it will automatically add the reenabling line at the end of the script.  But that’s odd as if they were disabled then I don’t think you should have got that message.

Can you check the first few lines of the sql file that you’re importing to see if it has the “SET FOREIGN_KEY_CHECKS = 0” in it?

 
Magento Community Magento Community
Magento Community
Magento Community
 
spiralmind
Member
 
Total Posts:  39
Joined:  2010-04-13
 

Hope this helps…

-- phpMyAdmin SQL Dump
-- version 3.4.5
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Oct 18, 2011 at 07:35 PM
-- Server version: 5.0.92
-- PHP Version: 5.2.6

SET FOREIGN_KEY_CHECKS=0;
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
SET AUTOCOMMIT=0;
START TRANSACTION;
SET time_zone = “+00:00”;

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;

--
-- Database: `nickspir_shop`
--

Do I need to enable foreign key checks again then somehow?

Many Thanks

 
Magento Community Magento Community
Magento Community
Magento Community
 
Tom Robertshaw
Guru
 
Avatar
Total Posts:  485
Joined:  2009-05-17
Bath, UK
 

If it’s there, it’ll be re-enabled at the end of the file.  That’s not your problem then.

Hmm, I’m not sure unfortunately.  Maybe someone else will have some magento 1.6 upgrade experience and be able to help.

 
Magento Community Magento Community
Magento Community
Magento Community
 
spiralmind
Member
 
Total Posts:  39
Joined:  2010-04-13
 

I have looked towards the end of the file and don’t see the re-enable line present where would it be..?

Would it work to run the SQL Query:

SET FOREIGN_KEY_CHECKS = 1;

through phpMyAdmin?

Note: old store was ver 1.5 I took sql backup through phpmyadmin and then on new server installed ver 1.6 and imported sql file from old store.

Thank you for your time it is very much appreciated, have been trying for 2 days with this now and tried many fresh install and different servers and keep getting this message.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Tom Robertshaw
Guru
 
Avatar
Total Posts:  485
Joined:  2009-05-17
Bath, UK
 

It should be almost the last line, if not the very last.

 
Magento Community Magento Community
Magento Community
Magento Community
 
spiralmind
Member
 
Total Posts:  39
Joined:  2010-04-13
 

This is the bottom of the sql file:

--
-- Constraints for table `catalog_category_flat_store_1`
--
ALTER TABLE `catalog_category_flat_store_1`
ADD CONSTRAINT `FK_CATEGORY_FLAT_CATEGORY_ID_STORE_1` FOREIGN KEY (`entity_id`) REFERENCES `catalog_category_entity` (`entity_id`) ON DELETE CASCADE ON UPDATE CASCADE,
ADD CONSTRAINT `FK_CATEGORY_FLAT_STORE_ID_STORE_1` FOREIGN KEY (`store_id`) REFERENCES `core_store` (`store_id`) ON DELETE CASCADE ON UPDATE CASCADE;
SET FOREIGN_KEY_CHECKS=1;
COMMIT;

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;

 
Magento Community Magento Community
Magento Community
Magento Community
 
spiralmind
Member
 
Total Posts:  39
Joined:  2010-04-13
 

Would anyone else have any more information what the problem is?

Thanks

 
Magento Community Magento Community
Magento Community
Magento Community
 
spiralmind
Member
 
Total Posts:  39
Joined:  2010-04-13
 

Would anyone else have more information on this error?

 
Magento Community Magento Community
Magento Community
Magento Community
 
ramanzeon
Jr. Member
 
Total Posts:  5
Joined:  2012-10-09
 

Guys need help here

http://www.magentocommerce.com/boards/viewthread/331965/

I am facing problem while creating category by code in Magento 1.6.
However my code works on Magento EE.

Below is my code,
$catModel = Mage::getModel(’catalog/category’);
$catModel->load();

$data[’entity_id’] = “”;
$data[’parent_id’] = 4;
$data[’path’] = ‘1/2’;
$data[’name’] = “Mike World”;
$data[’url_key’] = “digital-titles”;
$data[’url_path’] = “mike-world.html”;

$catModel->setData($data);

$catModel->save();

But I am getting error, as below :
a:5:{i:0;s:313:"SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails
(`magento_test`.`catalog_category_flat_store_1`, CONSTRAINT `FK_CAT_CTGR_FLAT_STORE_1_ENTT_ID_CAT_CTGR_ENTT_ENTT_ID` FOREIGN KEY (`entity_id`) REFERENCES `catalog_category_entity` (`enti)";i:1;s:1884:"#0 D:\wamp\www\test\lib\Varien\Db\Statement\Pdo\Mysql.php(110): Zend_Db_Statement_Pdo->_execute(Array)

Any help will be appreciated !!!

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top