{"record":{"id":"f2a09c7d9c361959","repo":"tursodatabase/turso","slug":"unable-to-access-database-schema-the-database-may","errorCode":null,"errorMessage":"Unable to access database schema. The database may be using an older SQLite version or may not be properly initialized.","messagePattern":"Unable to access database schema\\. The database may be using an older SQLite version or may not be properly initialized\\.","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"cli/app.rs","lineNumber":1659,"sourceCode":"                Some(ref tbl_name) => format!(\n                    \"SELECT name FROM {name}.sqlite_schema WHERE type='index' AND tbl_name = '{tbl_name}' ORDER BY 1\"\n                ),\n                None => format!(\"SELECT name FROM {name}.sqlite_schema WHERE type='index' ORDER BY 1\"),\n            };\n            let handler = |row: &turso_core::Row| {\n                if let Ok(Value::Text(idx)) = row.get::<&Value>(0) {\n                    if let Some(prefix) = prefix {\n                        indexes.push_str(prefix);\n                        indexes.push('.');\n                    }\n                    indexes.push_str(idx.as_str());\n                    indexes.push(' ');\n                }\n                Ok(())\n            };\n            if let Err(err) = self.handle_row(&sql, handler) {\n                if err.to_string().contains(\"no such table: sqlite_schema\") {\n                    return Err(anyhow::anyhow!(\"Unable to access database schema. The database may be using an older SQLite version or may not be properly initialized.\"));\n                } else {\n                    return Err(anyhow::anyhow!(\"Error querying schema: {}\", err));\n                }\n            }\n        }\n        if !indexes.is_empty() {\n            let _ = self.writeln(indexes.trim_end().as_bytes());\n        }\n        Ok(())\n    }\n\n    fn display_tables(&mut self, pattern: Option<&str>) -> anyhow::Result<()> {\n        let mut tables = String::new();\n\n        for name in self.database_names()? {\n            let prefix = (name != \"main\").then_some(&name);\n            let sql = match pattern {\n                Some(pattern) => format!(","sourceCodeStart":1641,"sourceCodeEnd":1677,"githubUrl":"https://github.com/tursodatabase/turso/blob/492c4a71cd7c2649e7df83da1471b74f4b1c7aa9/cli/app.rs#L1641-L1677","documentation":"Raised while listing indexes (.indexes) when the schema query fails with 'no such table: sqlite_schema'. The CLI string-matches that error and reports that the database cannot be inspected because it may predate sqlite_schema or is not properly initialized (cli/app.rs:1649). Everything else falls through to the generic wrapper.","triggerScenarios":"Running .indexes on a zero-byte placeholder file, on a database created by a very old SQLite that only has sqlite_master, or on a file that is not a SQLite database at all so no schema table exists.","commonSituations":"Pointing the CLI at an empty placeholder created with touch; opening a non-SQLite file by mistake; fixtures exported from legacy SQLite versions.","solutions":["Check you opened the intended path - wrong file is the most common cause","If the file is an empty placeholder, create any table to initialize the schema, then retry","Verify the file is a real SQLite database (header magic 'SQLite format 3', or open it with sqlite3)","For genuine legacy databases, convert with a current sqlite3 (open plus VACUUM INTO) before using tursodb"],"exampleFix":"# before\ntouch empty.db && tursodb empty.db\n# .indexes -> Unable to access database schema...\n# after\ntursodb real.db","handlingStrategy":"validation","validationCode":"let mut f = std::fs::File::open(&path)?;\nlet mut magic = [0u8; 16];\nf.read_exact(&mut magic)?;\nanyhow::ensure!(&magic == b\"SQLite format 3\\0\", \"not a SQLite database: {path}\");","typeGuard":"fn is_sqlite_file(header: &[u8]) -> bool {\n    header.starts_with(b\"SQLite format 3\\0\")\n}","tryCatchPattern":null,"preventionTips":["Check the 16-byte header magic before running schema dot-commands","Do not ship zero-byte placeholder files as databases","Convert legacy sqlite_master-era databases with a current sqlite3 first"],"tags":["cli","schema","sqlite-schema","indexes","legacy-db","rust"],"backgroundTag":"missing-system-table","analyzedSha":"492c4a71cd7c2649e7df83da1471b74f4b1c7aa9","analyzedAt":"2026-08-20T07:02:18.389Z","contentChangedAt":"2026-08-20T07:02:18.389Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}