Cause:
SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint
Actually, this means that the script could not create a foreign key constraint, since it is actually a mistake, but the reason for the failure is actually simple, mysql will not allow you to create an FK if the two fields you are trying to bind are not of the same type and lengths.
Now from line 31 of this update script you can really find the creation of a table with the addition of a foreign key constraint in the attribute_id field
$installer->run(" CREATE TABLE `{$installer->getTable('customer/form_attribute')}` ( `form_code` char(32) NOT NULL, `attribute_id` smallint UNSIGNED NOT NULL, PRIMARY KEY(`form_code`, `attribute_id`), KEY `IDX_CUSTOMER_FORM_ATTRIBUTE_ATTRIBUTE` (`attribute_id`), CONSTRAINT `FK_CUSTOMER_FORM_ATTRIBUTE_ATTRIBUTE` FOREIGN KEY (`attribute_id`) REFERENCES `{$installer->getTable('eav_attribute')}` (`attribute_id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Customer attributes/forms relations'; ");
But you can also see that the attribute_id field is created as the smallest, but without the length.
Since this link is to the eav_attribute table eav_attribute now you can try to compare the field type and the smallint field with the dummy table you created.
CREATE TABLE `dummy_table` (`attribute_id` smallint UNSIGNED NOT NULL) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Resolution:
So, if the eav_attribute.attribute_id field eav_attribute.attribute_id not smallint(5) unsigned not null , you can safely edit eav_attribute.attribute_id to make it smallint(5) unsigned not null .
If the field created in your dummy table is not smallint(5) unsigned not null , then just edit line 34 of the mysql4-upgrade-1.4.0.0.7-1.4.0.0.8.php so that the field is correctly created.
source share