0

I am inserting this magento database table in mysql database

CREATE TABLE `customer_address_entity` (
  `entity_id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Entity Id',
  `entity_type_id` smallint(5) unsigned NOT NULL DEFAULT '0' COMMENT 'Entity Type Id',
  `attribute_set_id` smallint(5) unsigned NOT NULL DEFAULT '0' COMMENT 'Attribute Set Id',
  `increment_id` varchar(50) DEFAULT NULL COMMENT 'Increment Id',
  `parent_id` int(10) unsigned DEFAULT NULL COMMENT 'Parent Id',
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'Created At',
  `updated_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT 'Updated At',
  `is_active` smallint(5) unsigned NOT NULL DEFAULT '1' COMMENT 'Is Active',
  PRIMARY KEY (`entity_id`),
  KEY `IDX_CUSTOMER_ADDRESS_ENTITY_PARENT_ID` (`parent_id`),
  CONSTRAINT `FK_CUSTOMER_ADDRESS_ENTITY_PARENT_ID_CUSTOMER_ENTITY_ENTITY_ID` FOREIGN KEY (`parent_id`) REFERENCES `customer_entity` (`entity_id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=96 DEFAULT CHARSET=utf8 COMMENT='Customer Address Entity';

But it is displaying error message

#1215 - Cannot add foreign key constraint

How can I fix this error ?

Bigtech Ideas
  • 105
  • 1
  • 4
  • 14
  • 3
    there are so many reasons this could appear, type mismatching/mismatch in records/etc etc etc... –  Oct 20 '14 at 12:38
  • 1
    does the `customer_entity` tables exist? or the table referenced in the foreign key definition is a typo? – guido Oct 20 '14 at 12:45
  • MrCoder Can you tell me basic 2 reasons ? – Bigtech Ideas Oct 20 '14 at 12:52
  • 1
    Yes, I would also think it has to do with the `customer_entity.entity_id` foreign key. Since we cannot see your database, we have no clue if this is really the problem. – KIKO Software Oct 20 '14 at 13:05
  • If I import whole database this error happen. "Fatal error: Maximum execution time of 300 seconds exceeded in E:\xampp\phpMyAdmin\libraries\dbi\mysqli.dbi.lib.php on line 267 " – Bigtech Ideas Oct 20 '14 at 13:44
  • But in php.ini file I have max_execution_time=64000 – Bigtech Ideas Oct 20 '14 at 13:44

1 Answers1

0
#1215 - Cannot add foreign key constraint

Error indicates that there is a problem with the reference of your foreign key 'customer_entity.entity_id'

You should check if:

  • the table 'customer_entity' exists
  • the column 'customer_entity.entity_id' exists
  • the types of 'customer_address_entity.parent_id' and 'customer_entity.entity_id' are exactly the same
  • the charset of tables 'customer_address_entity' and 'customer_entity' are the same

In any case, provide more information about your database's schema or at least more information for the involved tables.

Sevle
  • 3,109
  • 2
  • 19
  • 31
  • If I import whole database this error happen "If I import whole database this error happen Fatal error: Maximum execution time of 300 seconds exceeded in E:\xampp\phpMyAdmin\libraries\dbi\mysqli.dbi.lib.php on line 267" – Bigtech Ideas Oct 20 '14 at 13:40
  • 1
    @BigtechIdeas This problem seems different from the one specified in the original post. If you solved the original problem, you should consider creating a new thread for any followup issues you may have. You can also check if your answer is already answered before (perhaps here http://stackoverflow.com/questions/1263680/maximum-execution-time-in-phpmyadmin or there http://stackoverflow.com/questions/5164930/fatal-error-maximum-execution-time-of-30-seconds-exceeded) – Sevle Oct 20 '14 at 13:53