# Database documentation

**URL:** <https://forums.ankiweb.net/t/database-documentation/1157>\
**Category:** Development\
**Created:** [July 19, 2020, 9:37pm UTC](https://forums.ankiweb.net/t/database-documentation/1157 "2020-07-19T21:37:56Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![julien.baley](https://avatars.discourse-cdn.com/v4/letter/j/898d66/32.png) [@julien.baley](https://forums.ankiweb.net/u/julien.baley)\
**Post date:** [July 19, 2020, 9:37pm UTC](https://forums.ankiweb.net/t/database-documentation/1157/1 "2020-07-19T21:37:56Z")

</div>

Hello,

The database’s structure used to be documented by AnkiDroid at: [https://github.com/ankidroid/Anki-Android/wiki/Database-Structure](https://github.com/ankidroid/Anki-Android/wiki/Database-Structure) (and not by the main Anki project, as far as I’m aware).

It looks like the database schema has changed completely (somewhere between 2.1.13 and 2.1.28, i.e. on a “patch version”?): for instance, “SELECT decks FROM col” doesn’t return a JSON containing information about the decks anymore, but an error. Instead, the information seems to be in a “decks” table.

Is this documented anywhere? If it is, it doesn’t look like Google has noticed it, and I couldn’t find it in the manual ☹

---

<div class="post-metadata">

**Author:** ![dae](https://sea2.discourse-cdn.com/flex002/user_avatar/forums.ankiweb.net/dae/32/65_2.png) [@dae](https://forums.ankiweb.net/u/dae)\
**Post date:** [July 20, 2020, 1:19am UTC](https://forums.ankiweb.net/t/database-documentation/1157/2 "2020-07-20T01:19:13Z")

</div>

Where possible I recommend accessing the database via libanki, as it insulates you from the actual database layout. If you can’t do that, you’ll either need to update your code using Anki’s source as a guide, use the downgrade button, or export your collection to get a copy in an older schema version.

---

<div class="post-metadata">

**Author:** ![julien.baley](https://avatars.discourse-cdn.com/v4/letter/j/898d66/32.png) [@julien.baley](https://forums.ankiweb.net/u/julien.baley)\
**Post date:** [July 20, 2020, 6:18am UTC](https://forums.ankiweb.net/t/database-documentation/1157/3 "2020-07-20T06:18:26Z")

</div>

Oh, my use case is very simple and requires 2 simple queries (find deck ids based on deck names, and find cards in those decks), so I’ve managed to adapt the first one in a few minutes of looking around, but I was of course wondering if there was some documentation.  
Is there a documentation of libanki, too? When I wrote those programs, I remember it seemed much more difficult to learn to use libanki.

Perhaps appropriate to ask here: when I add new cards to a deck and use my program to list the content of a deck, it used to show those new cards immediately (had to sync, I believe). Now, however, it seems that syncing isn’t enough and that I must switch profile or close Anki for the new cards to appear in the DB. Is there something I can do to flush the new cards into the DB?

---

<div class="post-metadata">

**Author:** ![dae](https://sea2.discourse-cdn.com/flex002/user_avatar/forums.ankiweb.net/dae/32/65_2.png) [@dae](https://forums.ankiweb.net/u/dae)\
**Post date:** [July 21, 2020, 12:37am UTC](https://forums.ankiweb.net/t/database-documentation/1157/4 "2020-07-21T00:37:32Z")

</div>

The only docs at the moment are at [https://addon-docs.ankiweb.net/#/](https://addon-docs.ankiweb.net/#/)

Any outstanding changes are flushed at the start of the sync. Copying the db file while it’s open is not a use case sqlite tries to support however, so the behaviour there may be undefined.

---

<div class="post-metadata">

**Author:** ![flipside555](https://avatars.discourse-cdn.com/v4/letter/f/96bed5/32.png) [@flipside555](https://forums.ankiweb.net/u/flipside555)\
**Post date:** [July 24, 2022, 10:17am UTC](https://forums.ankiweb.net/t/database-documentation/1157/5 "2022-07-24T10:17:20Z")

</div>

> [@dae](#):
>
> Where possible I recommend accessing the database via libanki,

Is that this? [libanki · PyPI](https://pypi.org/project/libanki/#description)

---

<div class="post-metadata">

**Author:** ![dae](https://sea2.discourse-cdn.com/flex002/user_avatar/forums.ankiweb.net/dae/32/65_2.png) [@dae](https://forums.ankiweb.net/u/dae)\
**Post date:** [July 27, 2022, 9:05am UTC](https://forums.ankiweb.net/t/database-documentation/1157/7 "2022-07-27T09:05:17Z")

</div>

From the docs I linked above: [Command-Line Use - Writing Anki Add-ons](https://addon-docs.ankiweb.net/command-line-use.html)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex002/uploads/anki2/original/1X/8f1279ababc5879d54e4838989f606cfe55af8c7.jpeg) [@system](https://forums.ankiweb.net/u/system)\
**Post date:** [May 1, 2023, 3:14am UTC](https://forums.ankiweb.net/t/database-documentation/1157/8 "2023-05-01T03:14:58Z")

</div>

Closed on May 1, 2023, 3:14am UTC


