Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aimeos\MW\DB\Exception : SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint label:"help wanted" #252

Closed
penbosso opened this issue Dec 10, 2018 · 10 comments

Comments

@penbosso
Copy link

Environment

  1. Version (e.g. 2018.10)
  2. Operating system (Windows)

Describe the bug
I am trying to install aimeos for the first time using Laravel 5.7.* and got this error...

php artisan aimeos:setup
--option=setup/default/demo:1
Initializing or updating the Aimeos database tables for site "default"
Changing typeid of mshop_attribute table OK
Adding code column to mshop_catalog OK
Renaming product warehouse table OK
Adding ctime/mtime/user columns to tables
Renaming catalog index tables to index
Checking table "mshop_catalog_index_attribute" OK
Checking table "mshop_catalog_index_catalog" OK
Checking table "mshop_catalog_index_price" OK
Checking table "mshop_catalog_index_text" OK
Changing "domain" columns
Checking table "mshop_attribute": OK
Checking table "mshop_attribute_type": OK
Checking table "mshop_attribute_list_type": OK
Checking table "mshop_attribute_list": OK
Checking table "mshop_catalog": OK
Checking table "mshop_catalog_list_type": OK
Checking table "mshop_catalog_list": OK
Checking table "mshop_catalog_suggest": OK
Checking table "mshop_media_type": OK
Checking table "mshop_media_list_type": OK
Checking table "mshop_media": OK
Checking table "mshop_media_list": OK
Checking table "mshop_plugin": OK
Checking table "mshop_price": OK
Checking table "mshop_product_type": OK
Checking table "mshop_product_list_type": OK
Checking table "mshop_product_list": OK
Checking table "mshop_product_tag_type": OK
Checking table "mshop_service": OK
Checking table "mshop_service_list_type": OK
Checking table "mshop_service_list": OK
Checking table "mshop_text_type": OK
Checking table "mshop_text": OK
Checking table "mshop_text_list_type": OK
Checking table "mshop_text_list": OK
Adding mtime, ctime, editor columns to coupon tables
Checking table "mshop_coupon"
Checking table "mshop_coupon_code"
Checking table "mshop_order_base_coupon"
Migrating configuration keys in coupon tables OK
Adding status column to all list tables
Checking table "mshop_attribute_list": OK
Checking table "mshop_catalog_list": OK
Checking table "mshop_customer_list": OK
Checking table "mshop_media_list": OK
Checking table "mshop_price_list": OK
Checking table "mshop_product_list": OK
Checking table "mshop_service_list": OK
Checking table "mshop_text_list": OK
Changing typeid of mshop_media table OK
Adding id to order service attribute table
Checking column "id": OK
Adding siteid to order tables
Checking table "mshop_order_base": OK
Checking table "mshop_order": OK
Checking table "mshop_order_base_address": OK
Checking table "mshop_order_base_discount": OK
Checking table "mshop_order_base_product": OK
Checking table "mshop_order_base_service": OK
Checking table "mshop_order_base_product_attr": OK
Checking table "mshop_order_base_service_attr": OK
Adding product ID to order base product table
Checking table "mshop_order_base_product": OK
Adding warehouse code to order base product table OK
Adding service ID to order base service table
Checking table "mshop_order_base_service": OK
Migrating order address salutations
Checking table "mshop_order_base_address": OK
Adding tax column to order tables
Checking table "mshop_order_base_product": OK
Checking table "mshop_order_base_service": OK
Checking table "mshop_order_base": OK
Migrating order emailflag colum to order status list
Fixing order email status values OK
Migrating order flags to order status list
Migrating order type
Checking table "mshop_order": OK
Renaming order base customercode to customerid
Checking table "mshop_order_base": OK
Renaming order base product amount to quantity
Checking table "mshop_order_base_product": OK
Renaming order columns pdate,ddate,dstatus,pstatus
Checking columne "ddate": OK
Checking columne "pdate": OK
Checking columne "pstatus": OK
Checking columne "dstatus": OK
Renaming order domain
Checking table "mshop_order": OK
Checking table "mshop_order_base_address": OK
Checking table "mshop_order_base_service": OK
Renaming shipping to costs
Checking table "mshop_order_base": OK
Checking table "mshop_order_base_product": OK
Checking table "mshop_order_base_service": OK
Renaming column "discount" to "rebate"
Checking table "mshop_price" OK
Checking table "mshop_order_base" OK
Checking table "mshop_order_base_product" OK
Checking table "mshop_order_base_service" OK
Renaming column "price" to "value"
Checking table "mshop_price" OK
Renaming shipping to costs
Checking table "mshop_price": OK
Rename "prodid" to "parentid" in table "mshop_product_stock"
Checking column "prodid" OK
Changing code from "product" to "default" in "mshop_product_type" OK
Changing typeid column of product table
Checking table "mshop_product": OK
Migrating product property domain to "product" OK
Changing warehouseid column in mshop_product_stock OK
Rename warehouse table
Drop "mshop_product_stock.fk_msprost_whid" OK
Drop "mshop_product_stock.fk_msprost_stock_warehouseid" OK
Rename "mshop_product_stock.wareshouseid" OK
Rename "mshop_product_stock_wareshouse" OK
Move stock tables to own domain
Checking "mshop_product_stock" OK
Checking "mshop_product_stock_type" OK
Adding label and status columns for product warehouse
Ensure unique codes in mshop_service OK
Migrate product code in stock table
Moving product tag tables to own domain
Moving table "mshop_product_tag_type" OK
Moving table "mshop_product_tag" OK
Adding label to mshop text table OK
Changing typeid of mshop_text table OK
Adding parentid column to catalog and locale_site
Checking parentid column in "mshop_catalog" OK
Checking parentid column in "mshop_locale_site" OK
Remove left over Laravel user address records OK
Remove left over Laravel user list records OK
Creating base tables
Using schema from locale.php
Checking table "mshop_locale_site": done
Checking table "mshop_locale_language": done
Checking table "mshop_locale_currency": done
Checking table "mshop_locale": done
Using schema from attribute.php
Checking table "mshop_attribute_type": done
Checking table "mshop_attribute": done
Checking table "mshop_attribute_list_type": done
Checking table "mshop_attribute_list": done
Checking table "mshop_attribute_property_type": done
Checking table "mshop_attribute_property": done
Using schema from customer.php
Checking table "mshop_customer": done
Checking table "mshop_customer_address": done
Checking table "mshop_customer_list_type": done
Checking table "mshop_customer_list": done
Checking table "mshop_customer_group": done
Checking table "mshop_customer_property_type": done
Checking table "mshop_customer_property": done
Checking table "users": done
Checking table "users_address":
Aimeos\MW\DB\Exception : SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint

at E:\ck's menuenu\4th year\Project\web\code\inventhair\vendor\aimeos\aimeos-core\lib\mwlib\src\MW\DB\Statement\DBAL\Simple.php:91
87|
88| try {
89| $result = $this->exec();
90| } catch( \PDOException $e ) {

91| throw new \Aimeos\MW\DB\Exception( $e->getMessage(), $e->getCode() );
92| }
93|
94| return new \Aimeos\MW\DB\Result\PDO( $result );
95| }

Exception trace:

1 Aimeos\MW\DB\Statement\DBAL\Simple::execute()
E:\ck's menuenu\4th year\Project\web\code\inventhair\vendor\aimeos\aimeos-core\lib\mwlib\src\MW\Setup\Task\Base.php:153
2 Aimeos\MW\Setup\Task\Base::executeList("db-customer")
E:\ck's menuenu\4th year\Project\web\code\inventhair\vendor\aimeos\aimeos-core\lib\mshoplib\setup\TablesCreateMShop.php:197
Please use the argument -v to see more details.

@aimeos
Copy link
Owner

aimeos commented Dec 10, 2018

Do you have a type mismatch of users.id and users_address.parentid column?

@penbosso
Copy link
Author

it seem there is a mismatch.

@aimeos
Copy link
Owner

aimeos commented Dec 10, 2018

Can you post the output of

  • SHOW CREATE TABLE users
  • SHOW CREATE TABLE users_address

@penbosso
Copy link
Author

penbosso commented Dec 10, 2018

users CREATE TABLE users (  id int(11) NOT NULL AUTO_INCREMENT,  name varchar(255) COLLATE utf8_bin NOT NULL,  email varchar(255) COLLATE utf8_bin NOT NULL,  email_verified_at timestamp NULL DEFAULT NULL,  password varchar(255) COLLATE utf8_bin NOT NULL,  remember_token varchar(100) COLLATE utf8_bin DEFAULT NULL,  created_at datetime NOT NULL,  updated_at datetime NOT NULL,  superuser smallint(6) NOT NULL DEFAULT '0',  siteid int(11) DEFAULT NULL,  label varchar(255) COLLATE utf8_bin NOT NULL DEFAULT '',  salutation varchar(8) COLLATE utf8_bin NOT NULL DEFAULT '',  company varchar(100) COLLATE utf8_bin NOT NULL DEFAULT '',  vatid varchar(32) COLLATE utf8_bin NOT NULL DEFAULT '',  title varchar(64) COLLATE utf8_bin NOT NULL DEFAULT '',  firstname varchar(64) COLLATE utf8_bin NOT NULL DEFAULT '',  lastname varchar(64) COLLATE utf8_bin NOT NULL DEFAULT '',  address1 varchar(200) COLLATE utf8_bin NOT NULL DEFAULT '',  address2 varchar(200) COLLATE utf8_bin NOT NULL DEFAULT '',  address3 varchar(200) COLLATE utf8_bin NOT NULL DEFAULT '',  postal varchar(16) COLLATE utf8_bin NOT NULL DEFAULT '',  city varchar(200) COLLATE utf8_bin NOT NULL DEFAULT '',  state varchar(200) COLLATE utf8_bin NOT NULL DEFAULT '',  langid varchar(5) COLLATE utf8_bin DEFAULT NULL,  countryid char(2) COLLATE utf8_bin DEFAULT NULL,  telephone varchar(32) COLLATE utf8_bin NOT NULL DEFAULT '',  telefax varchar(32) COLLATE utf8_bin NOT NULL DEFAULT '',  website varchar(255) COLLATE utf8_bin NOT NULL DEFAULT '',  longitude decimal(8,6) DEFAULT NULL,  latitude decimal(8,6) DEFAULT NULL,  birthday date DEFAULT NULL,  vdate date DEFAULT NULL,  status smallint(6) NOT NULL DEFAULT '1',  editor varchar(255) COLLATE utf8_bin NOT NULL DEFAULT '',  PRIMARY KEY (id),  UNIQUE KEY users_email_unique (email),  KEY idx_lvusr_langid (langid),  KEY idx_lvusr_last_first (lastname,firstname),  KEY idx_lvusr_post_addr1 (postal,address1),  KEY idx_lvusr_post_city (postal,city),  KEY idx_lvusr_lastname (lastname),  KEY idx_lvusr_address1 (address1),  KEY idx_lvusr_city (city) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin
users_address CREATE TABLE users_address (  id int(11) NOT NULL AUTO_INCREMENT,  parentid int(11) NOT NULL,  siteid int(11) NOT NULL,  company varchar(100) COLLATE utf8_bin NOT NULL,  vatid varchar(32) COLLATE utf8_bin NOT NULL,  salutation varchar(8) COLLATE utf8_bin NOT NULL,  title varchar(64) COLLATE utf8_bin NOT NULL,  firstname varchar(64) COLLATE utf8_bin NOT NULL,  lastname varchar(64) COLLATE utf8_bin NOT NULL,  address1 varchar(200) COLLATE utf8_bin NOT NULL,  address2 varchar(200) COLLATE utf8_bin NOT NULL,  address3 varchar(200) COLLATE utf8_bin NOT NULL,  postal varchar(16) COLLATE utf8_bin NOT NULL,  city varchar(200) COLLATE utf8_bin NOT NULL,  state varchar(200) COLLATE utf8_bin NOT NULL,  langid varchar(5) COLLATE utf8_bin DEFAULT NULL,  countryid char(2) COLLATE utf8_bin DEFAULT NULL,  telephone varchar(32) COLLATE utf8_bin NOT NULL,  email varchar(255) COLLATE utf8_bin NOT NULL,  telefax varchar(255) COLLATE utf8_bin NOT NULL,  website varchar(255) COLLATE utf8_bin NOT NULL,  longitude decimal(8,6) DEFAULT NULL,  latitude decimal(8,6) DEFAULT NULL,  flag int(11) NOT NULL,  pos smallint(6) NOT NULL,  mtime datetime NOT NULL,  ctime datetime NOT NULL,  editor varchar(255) COLLATE utf8_bin NOT NULL,  PRIMARY KEY (id),  KEY idx_lvuad_pid (parentid),  KEY idx_lvuad_last_first (lastname,firstname),  KEY idx_lvuad_post_addr1 (postal,address1),  KEY idx_lvuad_post_city (postal,city),  KEY idx_lvuad_address1 (address1),  KEY idx_lvuad_city (city),  KEY idx_lvuad_email (email) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin

@aimeos
Copy link
Owner

aimeos commented Dec 10, 2018

Tables are OK. Do you have any records in users_address table?

@penbosso
Copy link
Author

No record in user_address table

@aimeos
Copy link
Owner

aimeos commented Dec 10, 2018

Found the problem: You users table uses ENGINE=MyISAM which makes it impossible to create a foreign key. Use InnoDb instead.

@penbosso
Copy link
Author

ALTER TABLE users ENGINE = InnoDB; corrected the table in the database

add 'engine' => 'InnoDB', to database connections will fix it in laravel

'connections' => [
'mysql' => [
'engine' => 'InnoDB',

@penbosso
Copy link
Author

Thanks

@nhakhtn
Copy link

nhakhtn commented Jul 16, 2022

you should go to table users then change the type of table from MyISAM to InnoDB, then it will be solved!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants