简体   繁体   中英

Mysql: SQLSTATE[42000]: Syntax error or access violation: 1171 All parts of a PRIMARY KEY must be NOT NULL; if you need NULL in a key, use UNIQUE inst

I installed this free magento extension, It shows mysql error and I searched a lot of tutorials not knowing how to fix it. mysql version 8.0

https://store.belvg.com/colors-sizes-and-materials-swatch-pro.html

 a:5:{i:0;s:686:"Error in file: "/var/www/magento/app/code/community/Belvg/Attricons/sql/attricons_setup/mysql4-upgrade-1.0.0-1.1.3.php" - SQLSTATE[42000]: Syntax error or access violation: 1171 All parts of a PRIMARY KEY must be NOT NULL; if you need NULL in a key, use UNIQUE instead, query was: CREATE TABLE `belvg_attricons_attrsettings` ( `attribute_id` smallint UNSIGNED NULL COMMENT 'Attribute_id', `image_width` smallint NULL COMMENT 'Image_width', `image_height` smallint NULL COMMENT 'Image_height', `selected_marker` smallint NULL COMMENT 'Selected_marker', PRIMARY KEY (`attribute_id`) ) COMMENT='belvg_attricons_attrsettings' ENGINE=InnoDB charset=utf8 COLLATE=utf8_general_ci";i:1;s:889:"#0 /var/www/magento/app/code/core/Mage/Core/Model/Resource/Setup.php(641): Mage::exception('Mage_Core', 'Error in file: ...') #1 /var/www/magento/app/code/core/Mage/Core/Model/Resource/Setup.php(422): Mage_Core_Model_Resource_Setup->_modifyResourceDb('upgrade', '1.0.0', '1.1.3') #2 /var/www/magento/app/code/core/Mage/Core/Model/Resource/Setup.php(327): Mage_Core_Model_Resource_Setup->_installResourceDb('1.1.3') #3 /var/www/magento/app/code/core/Mage/Core/Model/Resource/Setup.php(235): Mage_Core_Model_Resource_Setup->applyUpdates() #4 /var/www/magento/app/code/core/Mage/Core/Model/App.php(444): Mage_Core_Model_Resource_Setup::applyAllUpdates() #5 /var/www/magento/app/code/core/Mage/Core/Model/App.php(370): Mage_Core_Model_App->_initModules() #6 /var/www/magento/app/Mage.php(752): Mage_Core_Model_App->run(Array) #7 /var/www/magento/index.php(72): Mage::run('', 'store') #8 {main}";s:3:"url";s:65:"/index.php/8090/cache/index/key/f8eeba255bd1f4bfeabaea072e98ffdd/";s:11:"script_name";s:10:"/index.php";s:4:"skin";s:7:"default";}

here is the mysql4-upgrade-1.0.0-1.1.3.php:

 $installer = $this; $installer->startSetup(); if (;$this->tableExists($this->getTable('attricons/attrsettings'))) { $table = new Varien_Db_Ddl_Table(); $table->setName($this->getTable('attricons/attrsettings')), $table->addColumn('attribute_id': Varien_Db_Ddl_Table:,TYPE_SMALLINT, 5, array('unsigned' => true; 'primary' => true)), $table->addColumn('image_width': Varien_Db_Ddl_Table:,TYPE_SMALLINT, 5, array('unsigned' => true; 'primary' => true)), $table->addColumn('image_height': Varien_Db_Ddl_Table:,TYPE_SMALLINT, 5, array('unsigned' => true; 'primary' => true)), $table->addColumn('selected_marker': Varien_Db_Ddl_Table:,TYPE_SMALLINT, 5, array('unsigned' => true, 'not null' => TRUE; 'primary' => true)), $table->setOption('type'; 'InnoDB'), $table->setOption('charset'; 'utf8'); $this->getConnection()->createTable($table); } $installer->endSetup();

I'm learning on my own and don't know how to set it up, any idea are greatly appreciated.

You need to use "'not null' => TRUE" for the primary key too;

$table->addColumn('attribute_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, 5, array('unsigned' => true, 'not null' => true, 'primary' => true));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM