Relocate Existing Cards on Import

AnkiWeb addon 413327949

During .apkg import, moves existing duplicate or conflicting cards sharing the exact same GUID into the imported deck while preserving their scheduling and review history.
AI-generated summary; may contain mistakes.

importduplicatesdeck-managementbeta

Open on AnkiWeb GitHub Find alternatives

AnkiWeb

Votes
1 (πŸ‘ 1 Β· πŸ‘Ž 0)
Updated
2026-01-07
Anki versions
<=25.09.2
License
AGPL-3.0 (from the license file in the package)
Virus scan
No ClamAV match A match does not prove malware. No match does not prove that the code is safe.
Languages
HTML, Python, JavaScript, JSON, Ignore List
Description language
en

Maintenance

stale

  • Last update or commit: 2026-01-07 (298 days before the snapshot).
  • Commits in the last year: 7.
  • Issues: 0 open, 0 closed.
  • Pull requests: 0 open, 0 merged.

Will it work on my Anki?

Version branches
Min AnkiMax AnkiUpdated
25.09.2–2026-01-07
History across monthly snapshots

Loading…

Similar addons

MultiDeckImporter has 1 fork β†’

Imports multiple .apkg decks from a chosen folder at once, preserving the folder structure as nested parent decks; flat-structure importing is planned for a future version.

importdeck-management

23 votes 45% approval πŸ‘ 15 Β· πŸ‘Ž 8 ⭐ 1 Anki 2.1.30~ Updated 2020-08-20
Partial import from apkg file (mizmu)

Enables partial import of .apkg files by selecting cards through a card selection window with live preview, though duplicate checking currently does not work.

importfork-or-reupload

2 votes 34% approval πŸ‘ 2 Β· πŸ‘Ž 0 ⭐ 0 Anki 2.1.58~ Updated 2023-03-24

Description

This addon adds a handy feature to the import process: it allows you to automatically move your existing cards to the new deck you are importing, if they are detected as duplicates or conflicting.

This is useful if you have cards sitting in a generic deck (e.g., 'Default'). If these cards are also present in the imported .apkg file, the addon will automatically move them from 'Default' to the specific deck declared in the imported file.

How it Works

The addon hooks into Anki's import process to relocate cards. However, it operates under a Strict Identity Rule:

It only moves cards that share the exact same GUID (Global Unique Identifier) as the cards in the imported file.

It specifically looks for cards that Anki categorizes as:

  • Conflicting
  • Updated
  • Duplicate

If a card falls into any of these categories, the addon should moves your existing card to the deck specified in the imported file.

Scheduling Handling

  • Existing Cards: If the card already exists in your collection, the imported scheduling is ignored. Your current review history and intervals are preserved.
  • New Cards: If the card does not exist, it is added normally, and any scheduling information included in the file is imported without issues.

πŸš€ Future Roadmap

In the future I am considering implementing the following features to make the detection more flexible:

1. Content-Based Matching (Flexible Detection)

Currently, if a card has the exact same text as your existing card but a different GUID, it is ignored.

2. CSV / Text Support

Support for importing and relocating via CSV/Text files (comma-separated) is also being considered after implement Content-Based Matching

Best Practices & Limitations

To ensure the addon works correctly and to avoid data loss, please follow these rules:

1. Do NOT use Anki's Built-in "Merge" Options

When using the "Relocate" checkbox, do not select any of Anki's standard merge or update options (e.g., "Update notes," "Always," "If newer," etc.).

  • Why? The add-on doesn't handle Anki card updates well (it claims it does, but I haven't tested it much, to be honest).

  • Solution: If you need to update fields or merge content, perform the Relocate import first (with standard options disabled), and then run a second import specifically for merging/updating the note content.

2. Supported Formats

Currently, this feature only works with .apkg (Anki Package) files.

3. Experimental / "As-Is" Status

This is an intermediate solution developed to solve a specific personal use case. While it works for its intended purpose, it is not a native Anki feature.

  • My hope is that Anki developers might implement this natively in the future.
  • Until then, use this as a helpful tool, but be aware it is a personal project shared for anyone who may find it useful.

⚠️ Important Safety Warnings

Please read this carefully before installing:

1. πŸ’Ύ BACKUP YOUR COLLECTION FIRST

Before using this addon, please go to File > Export and create a backup of your collection. This addon deeply modifies how Anki handles your cards, so it is always better to be safe than sorry.

2. RECOMMENDATION: Use Once, Then Disable

This addon modifies internal Anki methods to work its magic. These methods were not originally designed to be changed by addons. My strong recommendation is:

  1. Enable the addon.
  2. Perform your Import.
  3. Disable or Uninstall the addon once you are done.

While the addon has been tested for imports, keeping it active during your daily study sessions could interfere with other Anki functions that I'm not aware.

Compatibility

  • Tested on: Anki 25.09.2
  • If you update Anki, this addon might stop working correctly due to internal changes in the app.

Issues & Feedback

If the addon does not work as expected, please report it on GitHub Issues. Since this is a personal project, immediate fixes aren't guaranteed, but reporting bugs helps me.

Scheenshots

Before Relocation

After Relocation

README

Relocate Cards on Import (Experimental)

This is a personal project released "as-is" for educational and learning purposes. I built this addon to solve a specific personal use case: moving existing cards to a new deck when importing. I am sharing the code for anyone interested in how it works or who wants to fork it, but I do not expect to maintain it actively.

Hopefully the devs could add this as a Built-in feature.

⚠️ Core Architecture & Warnings

Please read this before looking at the code:

This addon relies heavily on Monkey Patching internal Anki methods that are not part of the public API. Specifically, it overrides:

  • RustBackend.import_anki_package_raw (to intercept Protobuf messages).
  • Frontend injection using MutationObserver on Anki's Svelte components.

πŸ›‘ Known Risks

  1. High Breakage Potential: Since this patches internal methods, any update to Anki (especially to the Rust backend or the Import Dialog UI) will likely break this addon immediately.
  2. Limited Testing: This code has only been tested on the Import workflow. I have not tested if patching RustBackend causes side effects in other parts of Anki (e.g., syncing, exporting, or daily review).
  3. "Works on my Machine": It works for my specific workflow. I cannot guarantee it handles edge cases, different OS environments, or massive collection sizes gracefully.

πŸ›  Technical Implementation

If you are reviewing the code, here is the flow:

  1. Backend Patching: The addon wraps import_anki_package_raw. It lets the original method run, intercepts the ImportResponse (Protobuf), calculates which cards need moving, and modifies the deck IDs directly in the database logic.
  2. Frontend Injection: Since the Import Dialog uses Svelte, standard Qt hooks don't work for UI modification. The addon uses a MutationObserver to detect when the DOM is ready and injects the "Relocate" checkbox and the final status counter directly into the HTML.

πŸ€– AI Declaration

This project was developed with the assistance of Artificial Intelligence (LLMs). The AI was utilized for:

  • Generating boilerplate code for the Anki UI injection.
  • Educated me about how do some stuff and the anki source code, since its my first time reading and investigating any opensource code.

While AI assisted with the code generation, all logic was verified and tested manually for this specific use case.

βœ… Compatibility

  • Verified Version: Anki 25.09.2
  • OS: Windows (Code uses os.path, so it should be cross-platform, but untested).

🀝 Contributing / Issues

Since this was a personal fix:

  • Issues: You can open them to document bugs, but please don't expect immediate fixes.
  • Pull Requests: If you know how to fix a bug, refactor my horrible code (lol) or make the patch safer, feel free to submit a PR.

Use at your own risk.

License

AGPL v3