I am trying to upgrade magento to but I am getting the following error every time. I tried going to 1.6.2 as a test but having the same issue:

Error in file: "/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-" - 
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

I've run the DB repair script against a vanilla and all is fine.

Has anyone come across this issue before?

  • Was your Magento was fully patched before running the upgrade? – Mukesh Apr 30 at 16:58

In file app\code\core\Mage\Core\sql\core_setup\/mysql4-upgrade- look for INDEX_TYPE_UNIQUE and try to find some duplicate values for specific tables. I would supect some problem with core_url_rewrite (column id_path)


In table core_cache_tag you have to change the default value of columns tag and cache_id to a empty value ('') since they are both primary keys and not null.

This worked for me:

ALTER TABLE `core_cache_tag` 
CHANGE `cache_id` `cache_id` VARCHAR(200) NOT NULL DEFAULT '';

Updated solution

Turns out all these issues are due to the current versions of php and mysql being incompatible with magento 1.6, be certain to use the old versions of php and mysql and that may solve your issue.

Manual bypass solution

The issue is at lib/Varien/Db/Adapter/Pdo/Mysql.php line 1108 where it sets nullable=true when it shouldn't.

I was updating to version but I expect the issue is similar.

just wrap an if statement around it to prevent the error

if ($options['TABLE_NAME'] != 'salesrule_product_attribute' && $options['COLUMN_NAME'] != 'website_id') {
    $columnDefinition['nullable'] = true;

the original script assumes that since the foreign key can nullify the website_id when the original website_id is deleted that it is safe to assume that NULL is an acceptable default value. Obviously someone made a mistake setting up the original foreign key relationship since a primary key can't contain a null value.

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.