Codex Cannot Access Its Local Database — How to Fix It
Just updated Codex Desktop and now it won't open? You're seeing this scary message:
Codex cannot access its local database. The app cannot finish launching until its SQLite database is accessible. Most recent error: migration 1 was previously applied but has been modified
Don't worry. Your work is safe. This is a known bug, and the fix takes about two minutes.
Here's everything you need to know — the quick fix first, then the why.

Quick Fix (2 Minutes)
This is the fastest fix and it does not delete your chats or login.
- Fully close Codex. Quit the app completely. Check your system tray (bottom-right on Windows) and close it from there too.
- Open your
.codexfolder. Go to this path:- Windows:
C:\Users\<your-username>\.codex\ - Mac / Linux:
~/.codex/
- Windows:
- Find these two files and rename them (just add
.oldto the end so you have a backup):state_5.sqlite→state_5.sqlite.oldlogs_2.sqlite→logs_2.sqlite.old
- Restart Codex.
That's it. Codex will rebuild those two files automatically and open normally.
Important: Only touch those two
.sqlitefiles. Do NOT delete thesessionsfolder or theauthfiles inside.codex— that's where your chat history and login are stored.
Why This Error Happens
This error started showing up after the Codex Desktop 0.130 → 0.131 update (around May 2026). The auto-update changed something small inside the app's database files, and it no longer matched what was already saved on your computer.
In plain English: Codex keeps a small local database to track your settings and history. The update slightly changed the "blueprint" of that database, but your old file still followed the old blueprint. When the two don't match, Codex refuses to open — just to be safe.
The technical name for this is a migration mismatch (a "CRLF/LF checksum drift," if you want the nerdy version). It mostly hits Windows and WSL users, but Mac and Linux users have seen it too.
The good news: the two files causing the problem (state_5.sqlite and logs_2.sqlite) only hold metadata and indexing info. Your real conversations live in a separate sessions folder that this bug never touches. That's why deleting or renaming those two files is totally safe.
Read Now: OpenAI Codex Just Replaced My Junior Developer (Here's How)
What "Migration 1 Was Previously Applied But Has Been Modified" Actually Means
This is the part of the error that scares people the most, so let's break it down in plain English.
Codex keeps a small database on your computer to remember your settings, recent activity, and how things are organised. Every version of Codex expects that database to follow a certain "blueprint."
When you updated the app, the new version came with a slightly changed blueprint. But your old database file on disk still followed the old blueprint. So when Codex started up, it compared the two, saw they didn't match, and basically said: "This doesn't look right — I'm not opening until someone fixes it."
That mismatch is exactly what the message "migration 1 was previously applied but has been modified" is describing. A "migration" is just the technical word for updating a database's structure. Codex is telling you that a migration it already ran in the past no longer matches what it expects now.
The deeper cause is a CRLF/LF checksum drift — a tiny difference in how line endings got saved in the state_5.sqlite and logs_2.sqlite files. You don't need to understand that part. You just need to know it's harmless and easy to clear with the fix above.
If the Quick Fix Doesn't Work
Sometimes you'll see a slightly different version of the error, like:
attempt to write a readonly databasedatabase disk image is malformedtimed out waiting for state db backfill after 30s
Try these steps in order:
Step 1: Check if the file is corrupted
Open a terminal and run:
bash
sqlite3 ~/.codex/state_5.sqlite "pragma integrity_check;"
If it says anything other than ok, the file is damaged — renaming it (Quick Fix above) will solve it.
Step 2: Use the Repair / Reset option
The Codex app has a built-in Repair and Reset option. Try Repair first. If that fails, use Reset (this clears local data but keeps your account).
Step 3: Reinstall the app
If nothing works:
- Uninstall Codex
- Delete the
.codexfolder (back it up first if you want to keep old chats) - Reinstall Codex from the official source
- Sign in again
Step 4: Use a repair toolkit
A developer has published a free open-source tool called codex-repair on GitHub that fixes this exact crash automatically — without losing any conversations. It only touches the two problem files and leaves your chat history read-only the entire time. Search "xdifu codex-repair" on GitHub if you want the automated route.
Will I Lose My Chats or Login?
No. This is the most common worry, so let's be clear:
- Your chat history is stored in
~/.codex/sessions/— the fix never touches it. - Your login / auth is stored separately — you stay signed in.
- The only thing that gets rebuilt is the small metadata database, which Codex recreates fresh on the next launch.
The worst case is that your recent thread list takes a moment to re-index. Everything else stays exactly where it was.
How to Avoid This in the Future
This bug is tied to a specific bad update, and OpenAI is rolling out fixes. To stay safe:
- Back up your
.codexfolder before any major Codex update. - Don't run the Windows app and WSL CLI on the same database at the same time — that's a common trigger for this error.
- Keep Codex updated, since the team is patching these database issues quickly.
Read Now: GPT-5.1: Everything You Need to Know
Final Word
The "Codex cannot access its local database" error looks scary, but it's almost always harmless. Nine times out of ten, renaming state_5.sqlite and logs_2.sqlite and restarting the app fixes it in under two minutes — with zero data loss.
If you hit a more stubborn version of the error, the Repair tool or a clean reinstall will get you back up and running.
Now get back to coding.
FAQs
Does this error delete my Codex chat history?
No. Your chats are stored in a separate sessions folder that this fix never touches.
What causes "migration 1 was previously applied but has been modified"?
A mismatch between your old database file and the new app version after the 0.130 → 0.131 update. It's a known bug.
Where is the Codex local database stored?
In your .codex folder. On Windows: C:\Users\<username>\.codex\. On Mac/Linux: ~/.codex/.
Is it safe to delete state_5.sqlite?
Yes. It only holds metadata and indexing data. Codex rebuilds it automatically on the next launch.
Will I have to log in again after the fix?
No. Your login is stored separately and stays intact.
Does this affect the Codex CLI too?
It can, especially if you run the CLI and the Windows app on the same database folder. Avoid sharing the same .codex folder between them.
What does "migration 1 was previously applied but has been modified" mean?
It means your local Codex database no longer matches the new app version after the 0.130 → 0.131 update. The structure ("migration") it expects has changed. Renaming state_5.sqlite and logs_2.sqlite and restarting Codex fixes it.
What is "timed out waiting for state db backfill after 30s"?
A different message for the same bug. Codex got stuck rebuilding the database. The same 2-minute rename fix solves it.
I'm on Mac and see "database disk image is malformed." Same fix?
Yes. Your database file got corrupted during the update. Rename state_5.sqlite and logs_2.sqlite, then restart.
Why did this happen right after I updated Codex?
The 0.130 → 0.131 update changed the database structure, but your existing file still used the old structure. The mismatch blocks Codex from opening until the files are rebuilt.
Is this my computer's fault?
No. It's an OpenAI bug introduced by a specific update, and they're tracking it officially. Your hardware and files are fine.
Deeper technical guide: Fix Codex Database Errors: state_5.sqlite & Migration Issues — covers corrupted databases, failed migrations and lock errors in full, when the quick fix above is not enough.



0 Comments
Community guidelines
We want the comments to be useful for every reader. Every comment is reviewed before it is published. A comment will not be approved if it is:
Keep it genuine and on-topic and it will be approved quickly. Thank you for helping keep the discussion clean.