无法在 Laravel 项目的 ENV 文件中引用具有相对路径的 SQLite 数据库
Cannot reference SQLite database with relative path inside the ENV file of a Laravel project
我刚刚创建了一个 vanilla Laravel-React
项目,参考了以下 link:
https://github.com/napolev/laravel-react-vanilla
在这个项目中,我使用 SQLite
而不是 MySQL
。
我的问题是,当我为参数指定相对文件路径时:DB_DATABASE
,例如:database.sqlite
,我收到下面提到的错误。我尝试将前一个文件放在两个目录中:/
和 /database
但没有成功。另一方面,如果我指定前一个文件的完整路径:database.sqlite
,那么它可以正常工作。
这是:.env
文件:
https://github.com/napolev/laravel-react-vanilla/blob/master/.env#L11
# here a preview:
DB_CONNECTION=sqlite
# the following line is not working. it works with full path, though.
DB_DATABASE=database.sqlite
这是我遇到的错误:
Database (database.sqlite) does not exist.
(SQL: select * from "projects" order by "created_at" desc)
知道如何使用相对路径吗?例如,文件名:database.sqlite
或:database/database.sqlite
?
谢谢!
您检查过 laravel 文档了吗?
The database configuration for your application is located at config/database.php
. In this file you may define all of your database connections, as well as specify which connection should be used by default.
SQLite Configuration
After creating a new SQLite database using a command such as touch database/database.sqlite
, you can easily configure your environment variables to point to this newly created database by using the database's absolute path:
DB_CONNECTION=sqlite
DB_DATABASE=/absolute/path/to/database.sqlite
我刚刚创建了一个 vanilla Laravel-React
项目,参考了以下 link:
https://github.com/napolev/laravel-react-vanilla
在这个项目中,我使用 SQLite
而不是 MySQL
。
我的问题是,当我为参数指定相对文件路径时:DB_DATABASE
,例如:database.sqlite
,我收到下面提到的错误。我尝试将前一个文件放在两个目录中:/
和 /database
但没有成功。另一方面,如果我指定前一个文件的完整路径:database.sqlite
,那么它可以正常工作。
这是:.env
文件:
https://github.com/napolev/laravel-react-vanilla/blob/master/.env#L11
# here a preview:
DB_CONNECTION=sqlite
# the following line is not working. it works with full path, though.
DB_DATABASE=database.sqlite
这是我遇到的错误:
Database (database.sqlite) does not exist.
(SQL: select * from "projects" order by "created_at" desc)
知道如何使用相对路径吗?例如,文件名:database.sqlite
或:database/database.sqlite
?
谢谢!
您检查过 laravel 文档了吗?
The database configuration for your application is located at
config/database.php
. In this file you may define all of your database connections, as well as specify which connection should be used by default.SQLite Configuration After creating a new SQLite database using a command such as touch
database/database.sqlite
, you can easily configure your environment variables to point to this newly created database by using the database's absolute path:
DB_CONNECTION=sqlite
DB_DATABASE=/absolute/path/to/database.sqlite