I used Magento Data Migration Tool to import my database test2_web2.sql from to 2.2.3. Migration is successful with no issues.

If I export the database and then try to import it.

mysql -p -u test2_test test2_web2 < test2_web2.sql

The following error is displayed,

ERROR 1062 (23000) at line 368677: Duplicate entry '0' for key 'PRIMARY'

From my database Line 368677

ALTER TABLE cron_schedule

From within,

-- Indexes for table `cron_schedule`
**ALTER TABLE `cron_schedule`**
  ADD PRIMARY KEY (`schedule_id`),
  ADD KEY `CRON_SCHEDULE_SCHEDULED_AT_STATUS` (`scheduled_at`,`status`);

Does anyone know how I can resolve this?

  • Why you require to import again ? Apr 5, 2018 at 12:37
  • Means you want to import new data in Magento2? Apr 5, 2018 at 12:38
  • Importing again verifies the database. The data migration tool can miss errors that can later cause problems.
    – Stuart
    Apr 8, 2018 at 16:38

2 Answers 2


This was resolved by manually deleting cron_schedule

  • How did you manually delete cron_schedule? in the original database, or in the new database which you moved the files into?
    – styzzz
    May 20, 2018 at 13:56

In my case, the issue happens because the cron was running when importing.

The mysql dump I have is divided in 3 parts:

  1. Table creation
  2. Table key creation
  3. Table increment setting

If the cron is run between steps 1 and 2, it will create some rows in the cron_schedule table with the schedule_id field = 0 as there's no increment set yet, so effectively when it reaches step 2 the key creation will fail as there is more than one row with schedule_id = 0 and schedule_id is part of the key.

Of course you can also create another structure in the backup to do the key creation right after table creation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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