How do I mass delete duplicate cards with same template, same card type and same data?

I have a deck with many duplicate cards. The duplicate cards all have the same template, the same card type and the same data (I double checked the html) in the same fields. The deck uses a custom template and it’s notes should only generate one card type.These duplicates aren’t detected by ‘Tools → Detect Duplicate’.

I’m not exactly sure how this happened. I made the deck by using a custom Python script that generated a apkg file from a json file using the genanki Python module. It look awhile to fine-tune the script, so I created, imported and deleted the deck apkg file several times. I think I forgot to delete the previous deck the last time I created the deck. I think I merged the two decks. It might been something I did when I was fixing up the deck. I don’t know why Anki suddenly doesn’t seem to mind multiple duplicate cards with the same template and card type or why they don’t register as duplicates.

I don’t want to delete and recreate the deck, because I used it for awhile before I figured out this problem. I just want to delete the duplicate cards but keep all the other cards and metadata. Something like this:

  • If I haven’t reviewed any of the cards in note-> delete all but one card
  • If I have reviewed one of the cards in note-> keep card I have reviewed and delete rest
  • If I have reviewed several of the cards in note → keep card oldest card (first card I reviewed) and delete rest

I know the recommended way to delete an individual card is to empty the fields and use the “Empty Cards” option. However, if I do that it changes the data in the fields on both the cards (possibly because they are still the same template). The only way I have figured out to delete the individual duplicate cards to move one card into another deck, then delete that deck.

It would also really be a pain to do this for hundreds of cards. I can write scripts with Python, but I’m not sure where to start with this. I’m not sure this is something genanki does. I would appreciate some help. Thanks.

It’s not clear to me if those duplicate cards stem from the same note (Anki should complain about this), if there are actually duplicate notes with the same notetype (Anki should complain about this too) or if there are duplicate notes with different notetypes (I don’t know if Anki complains about that).

The duplicate cards appear to stem from the same note. Almost all notes in the deck have 2-3 duplicate cards each. I don’t see duplicate notes in my browser. I hope that clears things up.

This means you have several card templates per note. Go in the browser, select one of these notes, then go in Cards.... At the top, you should see a dropdown menu with the card templates. Check that there are some duplicates among them. If it’s the case, just remove the duplicates. This will automatically delete every duplicated card. Unfortunately, it’s not possible to save just the cards whose history is the oldest, because you can’t “simply” delete cards. You can delete a card template, and Anki will delete every card associated with that template.

There is only one card template for notes in the deck. I just double-checked. Only one entry under the “Card type” menu.

If it helps: if you truly have identical cards you can try Deck duplication - AnkiWeb - it has a “delete note clones” function (from right click on a deck in the browser) that will delete all identical notes (all fields the same) keeping only the oldest (i.e. the oldest creation date, so scheduling is not considered). Back up the deck before you try it.
Strike that, didn’t read the question properly, sorry. I understand that you have in fact just single copies of the notes but somehow too many cards are generated?

What you are describing, at least, how I understand it, is impossible. Each card has to “belong” to a note. If you have duplicated cards, either it’s a single note that “generated” both, or it’s multiple notes that generated these cards. However, you say that there is neither duplicate notes, nor that notes generate multiple cards…