# Set "lock" fields via sqlite?

**URL:** <https://forums.plex.tv/t/set-lock-fields-via-sqlite/734117>\
**Category:** Dev/API Corner\
**Tags:** server-windows, library-management\
**Created:** [August 5, 2021, 4:23pm UTC](https://forums.plex.tv/t/set-lock-fields-via-sqlite/734117 "2021-08-05T16:23:58Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![LegendaryLass](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/legendarylass/32/21855_2.png) [@LegendaryLass](https://forums.plex.tv/u/LegendaryLass)\
**Post date:** [August 5, 2021, 4:23pm UTC](https://forums.plex.tv/t/set-lock-fields-via-sqlite/734117/1 "2021-08-05T16:23:58Z")

</div>

Hi

I wrote a small python script to pull some additional genres and write them onto my tv shows. However, I don’t see a way to “lock” the genre field via the options in sqlite and it seems that whenever a new episode is added, Plex will refresh the whole series, wiping out my changes.

Is there any way to programatically set these locks? I’m assuming that lock will prevent the full-series-refresh that happens during the new episode refresh? (please correct me if I’m wrong!)

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![anon18523487](https://avatars.discourse-cdn.com/v4/letter/a/49beb7/32.png) [@anon18523487](https://forums.plex.tv/u/anon18523487)\
**Post date:** [August 5, 2021, 7:56pm UTC](https://forums.plex.tv/t/set-lock-fields-via-sqlite/734117/2 "2021-08-05T19:56:58Z")

</div>

Locking the fields will prevent the data changing during a refresh. Locking the fields is not an on/off thing. It’s in the “metadata\_items” table, “user\_fields” field. A locked entry looks like this:

lockedFields=2|6

Where the 2 and 6 are the specific fields. Lock the fields you want manually then check this field to identify the number you want to use. Then add this to the entries you want.

Edit: that is the pipe character between the values.

---

<div class="post-metadata">

**Author:** ![Volts](https://avatars.discourse-cdn.com/v4/letter/v/a5b964/32.png) [@Volts](https://forums.plex.tv/u/Volts)\
**Post date:** [August 5, 2021, 8:16pm UTC](https://forums.plex.tv/t/set-lock-fields-via-sqlite/734117/3 "2021-08-05T20:16:22Z")

</div>

Because `lockedFields` is pipe-delimited, I dislike editing it directly with SQLite.

So another option is to use the Plex HTTP API. There’s a nice example of how to do so, including locking **genre** , here:

> [@New Music Metadata handling](https://forums.plex.tv/t/new-music-metadata-handling/469988/10):
>
> Ahh, gotcha. There unfortunately no way to do that in the GUI. But of course you can edit your database directly and remove those locks on all items in one sweep. If you have access to the curl command or have an equivalent way of sending commands per http to your server, here is a sequence of commands to unlock them all. First you need to determine the library ID of your music library. You can get it from the [Plex XML info](https://support.plex.tv/hc/en-us/articles/201998867-Investigate-Media-Information-and-Formats "Plex XML info") of one of the music tracks (or by simply hovering the mouse cursor o…

I usually prefer to use the (unofficial) [Python PlexAPI](https://github.com/pkkid/python-plexapi) for this sort of thing.

---

<div class="post-metadata">

**Author:** ![OttoKerner](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/ottokerner/32/10079_2.png) [@OttoKerner](https://forums.plex.tv/u/OttoKerner)\
**Post date:** [August 5, 2021, 8:18pm UTC](https://forums.plex.tv/t/set-lock-fields-via-sqlite/734117/4 "2021-08-05T20:18:03Z")

</div>

For tv shows, you will need the right `type` number.  
I _think_ it is 2 for shows, 3 for seasons and 4 for episodes. I could be wrong though.

---

<div class="post-metadata">

**Author:** ![LegendaryLass](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/legendarylass/32/21855_2.png) [@LegendaryLass](https://forums.plex.tv/u/LegendaryLass)\
**Post date:** [August 5, 2021, 8:18pm UTC](https://forums.plex.tv/t/set-lock-fields-via-sqlite/734117/5 "2021-08-05T20:18:08Z")

</div>

thank you! that’s exactly what I need!!

---

<div class="post-metadata">

**Author:** ![LegendaryLass](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/legendarylass/32/21855_2.png) [@LegendaryLass](https://forums.plex.tv/u/LegendaryLass)\
**Post date:** [August 5, 2021, 8:19pm UTC](https://forums.plex.tv/t/set-lock-fields-via-sqlite/734117/6 "2021-08-05T20:19:02Z")

</div>

thanks! I liked someone else’s suggestion of lock the fields via the gui then check the table to see which number is dropped. “application is where the theory rubber meets the road” etc etc 🙂

---

<div class="post-metadata">

**Author:** ![Volts](https://avatars.discourse-cdn.com/v4/letter/v/a5b964/32.png) [@Volts](https://forums.plex.tv/u/Volts)\
**Post date:** [August 5, 2021, 8:21pm UTC](https://forums.plex.tv/t/set-lock-fields-via-sqlite/734117/7 "2021-08-05T20:21:10Z")

</div>

Some of the metadata\_item field IDs are listed here.

> [@Updating the PLEX database outside Plex - how?](https://forums.plex.tv/t/updating-the-plex-database-outside-plex-how/228547/5):
>
> Thanks. Just to finish off, my further investigation has revealed the following, documented here for use by others who may be in similar situation: Index appears to be 0-based, not 1-based (may not matter in the end) Index is “per-tag-type”, ie. all Director tags (tag\_type=4) have different index numbering from all Collection tags (tag\_type=2). In the table tags (which contain ALL tage for ALL media in the database), the field tag\_type can have the following values (these are just the ones I h…
