SQLite 无法打开数据库文件:Laravel + Windows
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30382554/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
SQLite unable to open database file: Laravel + Windows
提问by Miguel Borges
I'm try use a sqlite database in my laravel project, in local environment for dev (Windows 8.1 with AMMPS), but when I try run a migrate:instal
command, this error apeear:
我尝试在我的 laravel 项目中使用 sqlite 数据库,在本地环境中用于 dev(带有 AMMPS 的 Windows 8.1),但是当我尝试运行migrate:instal
命令时,出现此错误:
[PDOException] SQLSTATE[HY000] [14] unable to open database file
[PDOException] SQLSTATE[HY000] [14] 无法打开数据库文件
My database config file (app/config/local/database.php):
我的数据库配置文件(app/config/local/database.php):
<?php
return array(
'default' => 'sqlite',
'connections' => array(
'sqlite' => array(
'driver' => 'sqlite',
'database' => __DIR__ . '\..\..\database\production.sqlite',
'prefix' => '',
),
),
);
回答by Said Bouigherdaine
try to remove the DB_DATABASE="yourdatabase" variable in your .env file
尝试删除 .env 文件中的 DB_DATABASE="yourdatabase" 变量
回答by french_dev
If the permissions allow to write on the folder just create the storage folders.
如果权限允许在文件夹上写入,只需创建存储文件夹。
e-g, this how I fix the problem.
例如,这是我解决问题的方式。
in config/database.php
:
在config/database.php
:
'connections' => [
'sqlite' => [
'driver' => 'sqlite',
'database' => storage_path('database/databaseName.sqlite'),
'prefix' => '',
],
Then if you run on your terminal php artisan migrate
, it returns you the [PDOException] SQLSTATE[HY000] [14] unable to open database file
然后,如果您在终端上运行php artisan migrate
,它会返回给您[PDOException] SQLSTATE[HY000] [14] unable to open database file
Create the path folder by your own, e-g in your terminal mkdir storage/database/databaseName.sqlite
自行创建路径文件夹,例如在您的终端中 mkdir storage/database/databaseName.sqlite
Make sure the permissions allow you to write, then re-run the command php artisan migrate
, it returns you the success message : Migration table created successfully
.
确保权限允许您写入,然后重新运行该命令php artisan migrate
,它会返回成功消息:Migration table created successfully
。
回答by Terry
You just need to make sqlite file available at the defined path. In larvel 5.7, I just used following command and run migration.
您只需要在定义的路径中使 sqlite 文件可用。在 larvel 5.7 中,我只使用以下命令并运行迁移。
touch /absolute/path/of/db.sqlite
That will create an empty file at defined location and you are good to go.
这将在定义的位置创建一个空文件,你很高兴。
Observation: In Larvel 5.7, .sqlite file should be already available at defined location.
观察:在 Larvel 5.7 中,.sqlite 文件应该已经在定义的位置可用。
For windows, right click and create new file with the defined name at defined location.
对于 Windows,右键单击并在定义的位置创建具有定义名称的新文件。
回答by user2130131
On laravel 5.3.x
在 Laravel 5.3.x 上
This was the only thing that worked for me:
这是唯一对我有用的东西:
Change DB_CONNECTION from "mysql" to "sqlite". Because this is an sqlite database, you can delete all the other DB_* items in that .env file.
APP_ENV=local APP_KEY=base64: APP_DEBUG=true APP_LOG_LEVEL=debug APP_URL=http://localhost
DB_CONNECTION=sqlite
将 DB_CONNECTION 从“mysql”更改为“sqlite”。因为这是一个 sqlite 数据库,所以您可以删除该 .env 文件中的所有其他 DB_* 项目。
APP_ENV=本地 APP_KEY=base64: APP_DEBUG=true APP_LOG_LEVEL=debug APP_URL= http://localhost
DB_CONNECTION=sqlite
回答by Nathan Macedo
try change the file databaseName.sqlite
permission database to writeable and readable. Maybe change permissions folder database
also.
尝试将文件databaseName.sqlite
权限数据库更改为可写和可读。也许也更改权限文件夹database
。
In the production server change this file database to private directory for security.
在生产服务器中,为了安全起见,将此文件数据库更改为私有目录。
回答by Sazzadur Rahman
Well it may be late but I have also faced the problem in ubuntu
environment, here exactly how I overcome this issue.
好吧,可能已经晚了,但我也遇到了ubuntu
环境问题,这正是我如何克服这个问题的。
You have to pass your fully qualified sqlite
file's path to your .env
file, like following:
您必须将完全限定sqlite
文件的路径传递给您的.env
文件,如下所示:
DB_CONNECTION=sqlite
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE="/var/www/html/my-awesome-project/database/database.sqlite"
DB_USERNAME=homestead
DB_PASSWORD=secret
Here change the value of DB_DATABASE
key to the exact location of your sqlite
file in your computer's filesystem.
在这里将DB_DATABASE
key的值更改为您的sqlite
文件在计算机文件系统中的确切位置。
Tips:You can find your database's path for sqlite
file by adding
提示:您可以sqlite
通过添加来找到数据库的文件路径
dd(database_path('database.sqlite'));
this line of code in the top of config/database.php
file and run php artisan migrate
to terminal. You can find the exact location from there, copy it and put it to .env
s DB_DATABASE
key.
这行代码在config/database.php
文件顶部并运行php artisan migrate
到终端。您可以从那里找到确切的位置,将其复制并放入.env
sDB_DATABASE
键。
Don't forget to restart laravel server and remove dd(database_path('database.sqlite'));
form database.php
before testing.
在测试之前不要忘记重新启动 Laravel 服务器并删除dd(database_path('database.sqlite'));
表单database.php
。
回答by R Sun
In my case, changing url: '%env(DATABASE_AUTH_URL)%'
to url: '%env(resolve:AUTH_DATABASE_URL)%'
fixed the issue
就我而言,更改url: '%env(DATABASE_AUTH_URL)%'
以url: '%env(resolve:AUTH_DATABASE_URL)%'
解决问题
回答by Malek Ben el ouafi
Please check the permissions of the directory that database file is stored in. chmod 777 YOU_APP/database
请检查数据库文件所在目录的权限。 chmod 777 YOU_APP/database
回答by Dutchy
Change DB_CONNECTION
from "mysql" to "sqlite".
Because this is an sqlite database, you can delete all the other DB_*
items in that .env
file.
DB_CONNECTION
从“mysql”更改为“sqlite”。因为这是一个 sqlite 数据库,所以您可以删除DB_*
该.env
文件中的所有其他项目。
APP_ENV=local
APP_KEY=base64:
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=http://localhost
DB_CONNECTION=sqlite