1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【Cloudflare】unable to read sql text file "./db/schema.sql". please check the file path and try again.の解決方法

Last updated at Posted at 2025-10-08

はじめに

CloudflareD1を使用してデータベースを作成している際に発生したエラーについてまとめます。今回は、ドキュメント通りにコマンドを実行したにもかかわらずエラーが出たケースの原因と解決方法を紹介します。

この記事は個人的なアウトプットを目的として作成したものです。そのため、誤った情報や不足している内容が含まれている可能性があります。もし間違いや気になる点がございましたら、ぜひご指摘いただけますと幸いです

現象

下記の公式ドキュメントに沿ってデータベースの設定を進めていました。

手順「5. アプリケーションをデプロイする」で次のコマンドを実行した際にエラーが発生しました。

npx wrangler d1 execute prod-d1-tutorial --remote --file=./schema.sql

すると、以下のようなエラーが表示されました。

unable to read sql text file "./db/schema.sql". please check the file path and try again

ファイルパスの指定に問題があるという内容ですが、実際には前のステップ
「4. D1データベースに対してクエリを実行する」で、ローカル環境に対して同様のコマンドを実行できていました。

npx wrangler d1 execute prod-d1-tutorial --local --file=./schema.sql

原因

調査した結果、schema.sqlファイル自体がプロジェクト内から削除されていたことが原因でした。つまり、Cloudflareがファイルを見つけられなかったために「ファイルが読めません」というエラーになっていました。

手順通りにローカルで実行した際は問題なかったため、作業の途中で誤って削除してしまった可能性があります。

解決方法

scehma.sqlファイルを再度追加することでエラーが解消されました。
再作成後にパスを確認し、再度コマンドを実行したところ正常に処理が完了しました。

npx wrangler d1 execute prod-d1-tutorial --remote --file=./schema.sql
# ✅ 正常に実行できた

終わりに

今回のエラーは単純に「SQLファイルが存在しなかった」ことが原因でした。引き続き学習を進めていきます。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?