This can usually be fixed by doing the following:
1. Create a batch of any orders in the orders file.
2. For your records, we recommend that you print or export to a flat file all batch orders.
3. Process any pending orders that may be there using the Process Orders feature.
4. Delete all batches from Miva.
5. Delete/Recover All Shopping Carts. Do not recover Order IDs when you
recover all shopping carts. This is what causes the duplicate key
error.
6. Finally, pack the data files from the Stores >> Your Store Name >> Utilities >> Pack Data Files menu.