laravel8でsqlite使うときは空ファイルを事前に作成しておくこと
sqliteでmigrateしたときにエラーになって進まなかったので、調査しました。 本エントリは、その結果です。
事象
create-project でlaravelプロジェクトを作成して、.envを以下のように修正
DB_CONNECTION=sqlite #DB_CONNECTION=mysql #DB_HOST=127.0.0.1 #DB_PORT=3306 #DB_DATABASE=laravel #DB_USERNAME=root #DB_PASSWORD=
そして、migrate 実行
[username@hostname~/appname]$ php artisan migrate
以下のエラーが発生
Database (/home/username/appname/database/database.sqlite) does not exist. (SQL: PRAGMA foreign_keys = ON;)
at vendor/laravel/framework/src/Illuminate/Database/Connection.php:678
// If an exception occurs when attempting to run a query, we'll format the error // message to include the bindings with SQL, which will make this exception a // lot more helpful to the developer instead of just the database's errors. catch (Exception $e) { throw new QueryException( $query, $this->prepareBindings($bindings), $e ); }
対応
事前にデータベース用の空ファイルを作っておく
[username@hostname~/appname]$ touch database/database.sqlite [username@hostname~/appname]$ php artisan migrate
参考
ドキュメントに書いてました。