3

I recently updated from magento v. 2.1.7 to 2.1.9 and then tried to update directly after that to 2.2.1. That failed and when i try to do a rollback (backup created before updating from 2.1.7) that also fails so I am stuck between working versions. The error I get when trying to rollback database is this:

SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint, query was: CREATE TABLE `customer_group` (
  `customer_group_id` smallint(5) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Customer Group Id',
  `customer_group_code` varchar(32) NOT NULL COMMENT 'Customer Group Code',
  `tax_class_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT 'Tax Class Id',
  PRIMARY KEY (`customer_group_id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 COMMENT='Customer Group';
4

Since the 2.2.0 release the customer_group_id field has type INT(10):

CREATE TABLE `customer_group` (
 `customer_group_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `customer_group_code` varchar(32) NOT NULL COMMENT 'Customer Group Code',
 `tax_class_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT 'Tax Class Id',
 PRIMARY KEY (`customer_group_id`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8 COMMENT='Customer Group'

You can update this table manually or check why during update the old type is used.

This is actual for the all tables where the customer_group_id field used as a foreign key: its length should be changed to the 10.

| improve this answer | |
  • @sandip I'm glad to help You :) – Siarhey Uchukhlebau Jan 3 '18 at 11:37
  • can this schema change be skipped when very few customer groups are used? problem is when you have 600gb db it will take ages to alter the column and i'm not sure is useful when you are only a b2c seller – Antonio Pedicini Sep 18 '18 at 16:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.