Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Magento1 issues with out of range value_id
DELETE FROM catalog_product_entity_datetime WHERE entity_id NOT IN (SELECT entity_id FROM catalog_product_entity);
DELETE FROM catalog_product_entity_datetime WHERE attribute_id NOT IN (SELECT attribute_id FROM eav_attribute);
DELETE FROM catalog_product_entity_decimal WHERE entity_id NOT IN (SELECT entity_id FROM catalog_product_entity);
DELETE FROM catalog_product_entity_decimal WHERE attribute_id NOT IN (SELECT attribute_id FROM eav_attribute);
DELETE FROM catalog_product_entity_int WHERE entity_id NOT IN (SELECT entity_id FROM catalog_product_entity);
DELETE FROM catalog_product_entity_int WHERE attribute_id NOT IN (SELECT attribute_id FROM eav_attribute);
DELETE FROM catalog_product_entity_text WHERE entity_id NOT IN (SELECT entity_id FROM catalog_product_entity);
DELETE FROM catalog_product_entity_text WHERE attribute_id NOT IN (SELECT attribute_id FROM eav_attribute);
DELETE FROM catalog_product_entity_varchar WHERE entity_id NOT IN (SELECT entity_id FROM catalog_product_entity);
DELETE FROM catalog_product_entity_varchar WHERE attribute_id NOT IN (SELECT attribute_id FROM eav_attribute);
-- DATETIME
CREATE TABLE `catalog_product_entity_datetime_old` (
`value_id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'Value ID',
`entity_type_id` smallint(5) unsigned NOT NULL COMMENT 'Entity Type ID',
`attribute_id` smallint(5) unsigned NOT NULL COMMENT 'Attribute ID',
`store_id` smallint(5) unsigned NOT NULL COMMENT 'Store ID',
`entity_id` int(10) unsigned NOT NULL COMMENT 'Entity ID',
`value` datetime DEFAULT NULL COMMENT 'Value',
PRIMARY KEY (`value_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Catalog Product Datetime Attribute Backend Table';
INSERT INTO catalog_product_entity_datetime_old (entity_type_id, attribute_id, store_id, entity_id, value)
SELECT entity_type_id, attribute_id, store_id, entity_id, value FROM catalog_product_entity_datetime;
DELETE FROM catalog_product_entity_datetime;
ALTER TABLE catalog_product_entity_datetime AUTO_INCREMENT = 1;
INSERT INTO catalog_product_entity_datetime (entity_type_id, attribute_id, store_id, entity_id, value)
SELECT entity_type_id, attribute_id, store_id, entity_id, value FROM catalog_product_entity_datetime_old;
-- DECIMAL
CREATE TABLE `catalog_product_entity_decimal_old` (
`value_id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'Value ID',
`entity_type_id` smallint(5) unsigned NOT NULL COMMENT 'Entity Type ID',
`attribute_id` smallint(5) unsigned NOT NULL COMMENT 'Attribute ID',
`store_id` smallint(5) unsigned NOT NULL COMMENT 'Store ID',
`entity_id` int(10) unsigned NOT NULL COMMENT 'Entity ID',
`value` decimal(12,4) DEFAULT NULL COMMENT 'Value',
PRIMARY KEY (`value_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO catalog_product_entity_decimal_old (entity_type_id, attribute_id, store_id, entity_id, value)
SELECT entity_type_id, attribute_id, store_id, entity_id, value FROM catalog_product_entity_decimal;
DELETE FROM catalog_product_entity_decimal;
ALTER TABLE catalog_product_entity_decimal AUTO_INCREMENT = 1;
INSERT INTO catalog_product_entity_decimal (entity_type_id, attribute_id, store_id, entity_id, value)
SELECT entity_type_id, attribute_id, store_id, entity_id, value FROM catalog_product_entity_decimal_old;
-- INT
CREATE TABLE `catalog_product_entity_int_old` (
`value_id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'Value ID',
`entity_type_id` smallint(5) unsigned NOT NULL COMMENT 'Entity Type ID',
`attribute_id` smallint(5) unsigned NOT NULL COMMENT 'Attribute ID',
`store_id` smallint(5) unsigned NOT NULL COMMENT 'Store ID',
`entity_id` int(10) unsigned NOT NULL COMMENT 'Entity ID',
`value` int(11) DEFAULT NULL COMMENT 'Value',
PRIMARY KEY (`value_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO catalog_product_entity_int_old (entity_type_id, attribute_id, store_id, entity_id, value)
SELECT entity_type_id, attribute_id, store_id, entity_id, value FROM catalog_product_entity_int;
DELETE FROM catalog_product_entity_int;
ALTER TABLE catalog_product_entity_int AUTO_INCREMENT = 1;
INSERT INTO catalog_product_entity_int (entity_type_id, attribute_id, store_id, entity_id, value)
SELECT entity_type_id, attribute_id, store_id, entity_id, value FROM catalog_product_entity_int_old;
-- TEXT
CREATE TABLE `catalog_product_entity_text_old` (
`value_id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'Value ID',
`entity_type_id` smallint(5) unsigned NOT NULL COMMENT 'Entity Type ID',
`attribute_id` smallint(5) unsigned NOT NULL COMMENT 'Attribute ID',
`store_id` smallint(5) unsigned NOT NULL COMMENT 'Store ID',
`entity_id` int(10) unsigned NOT NULL COMMENT 'Entity ID',
`value` text DEFAULT NULL COMMENT 'Value',
PRIMARY KEY (`value_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO catalog_product_entity_text_old (entity_type_id, attribute_id, store_id, entity_id, value)
SELECT entity_type_id, attribute_id, store_id, entity_id, value FROM catalog_product_entity_text;
DELETE FROM catalog_product_entity_text;
ALTER TABLE catalog_product_entity_text AUTO_INCREMENT = 1;
INSERT INTO catalog_product_entity_text (entity_type_id, attribute_id, store_id, entity_id, value)
SELECT entity_type_id, attribute_id, store_id, entity_id, value FROM catalog_product_entity_text_old;
-- Varchar
CREATE TABLE `catalog_product_entity_varchar_old` (
`value_id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'Value ID',
`entity_type_id` smallint(5) unsigned NOT NULL COMMENT 'Entity Type ID',
`attribute_id` smallint(5) unsigned NOT NULL COMMENT 'Attribute ID',
`store_id` smallint(5) unsigned NOT NULL COMMENT 'Store ID',
`entity_id` int(10) unsigned NOT NULL COMMENT 'Entity ID',
`value` varchar(255) DEFAULT NULL COMMENT 'Value',
PRIMARY KEY (`value_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO catalog_product_entity_varchar_old (entity_type_id, attribute_id, store_id, entity_id, value)
SELECT entity_type_id, attribute_id, store_id, entity_id, value FROM catalog_product_entity_varchar;
DELETE FROM catalog_product_entity_varchar;
ALTER TABLE catalog_product_entity_varchar AUTO_INCREMENT = 1;
INSERT INTO catalog_product_entity_varchar (entity_type_id, attribute_id, store_id, entity_id, value)
SELECT entity_type_id, attribute_id, store_id, entity_id, value FROM catalog_product_entity_varchar_old;
DROP TABLE IF EXISTS catalog_product_entity_datetime_old;
DROP TABLE IF EXISTS catalog_product_entity_decimal_old;
DROP TABLE IF EXISTS catalog_product_entity_int_old;
DROP TABLE IF EXISTS catalog_product_entity_text_old;
DROP TABLE IF EXISTS catalog_product_entity_varchar_old;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment