You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Expo SQLite API加载预填充数据库报错:找不到预填充文件中的表

Hey, I’ve run into this exact issue before with Expo’s SQLite API—super frustrating when you’ve got the DB file in place but still get that table error. Let’s walk through the most likely fixes step by step:

Troubleshooting "no such table in pre-populated file" Error in Expo SQLite

1. Double-check your database path and openDatabase configuration

  • First, make sure the name parameter in openDatabase matches your actual database filename exactly, including capitalization (Android is case-sensitive for filenames, while iOS isn’t—this is a common gotcha).
  • If your DB is stored in the assets folder, confirm it’s added to assetBundlePatterns in app.json so Expo bundles it with your app:
    "assetBundlePatterns": [
      "**/*",
      "assets/databases/your-db-file.db"
    ]
    
  • Use the correct createFromLocation parameter for your Expo SDK version:
    • For SDK 48+: Use createFromAsset with a require statement pointing to your DB file
    • For older SDKs: Use createFromLocation: 1 (which tells Expo to copy from the assets folder)
      Example code:
    const db = SQLite.openDatabase({
      name: 'your-db.db',
      location: 'default',
      // SDK 48+ syntax
      createFromAsset: require('./assets/your-db.db')
      // Older SDK syntax
      // createFromLocation: 1
    });
    

2. Verify your pre-populated database file is valid

  • Open your local DB file with a tool like DB Browser for SQLite to confirm:
    • The table you’re querying actually exists
    • The table name matches exactly what you’re using in your SQL statements (watch for typos, underscores, or capitalization differences)
  • Check if the DB file is corrupted—sometimes copying or exporting the file can introduce errors. Try re-exporting a fresh version from your SQLite tool.

3. Clear Expo’s cache and rebuild the project

Expo often caches old assets, especially if you’ve updated your DB file. Try these steps:

  • Close the Expo Go client completely and reopen it
  • Run expo r -c in your terminal to clear the cache and restart the dev server
  • For simulators: Reset iOS simulator content or clear Android app data to wipe any cached DB copies

4. Ensure the database finishes copying before running queries

If you’re executing SQL statements immediately on app launch, the pre-populated DB might not have finished copying yet. Add a safety check:

  • Wrap your queries in a try/catch block to handle initialization delays
  • Add a small delay (or use a state flag) to wait for the database to open before running operations

5. Check platform-specific quirks

  • Android: Make sure your DB file doesn’t have read-only permissions. Also, stick with location: 'default' to let Expo handle the correct storage path automatically.
  • iOS: If distributing via TestFlight/Ad Hoc, verify the DB file is included in the IPA bundle. You can check this in Xcode by inspecting the app’s bundled resources.

内容的提问来源于stack exchange,提问作者Eric Phillips

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 07:01:32