Inv*_*tax 1 php sqlite laravel
我使用 SQLite 数据库创建了一个新的 Laravel 应用程序作为用户登录系统。我遇到一个奇怪的问题,收到以下错误:
Run Code Online (Sandbox Code Playgroud)> SQLSTATE[HY000]: General error: 8 attempt to write a readonly database > (SQL: update "users" set "remember_token" = > HH0dtQYZ5BgoOpya1hNRUrFvIZF0dcYqdIvAjz0k6CbTKBqah7wWPdQbgzzL, > "updated_at" = 2016-06-18 12:47:43 where "id" = 1)
我最初认为我的 SQLite 数据库文件存在一些权限问题,但是正确的用户有权访问该文件,并且我已将 chmod 设置为755. 该问题仅在第一次登录时发生,如果我刷新页面(并重新发送表单数据),应用程序将成功登录。我的应用程序中的任何其他数据库操作都没有遇到此问题。
对于任何可能需要此操作的人,请检查您的文件权限。
如果您的database.sqlite文件位于 下database/,请将权限设置为 775(755 对我不起作用)。
$ chmod -R 775 database
Run Code Online (Sandbox Code Playgroud)
It may also be worth setting the group to www-data and owner to yourself.
$ chgrp -R www-data database
$ chown -R USERNAME database
Run Code Online (Sandbox Code Playgroud)
obviously replace database with the path to the folder your .sqlite database is. Also check the permissions after any migrations commands, or passport:install. I'm sure it was user error, but at one point I thought I had set file permissions on the directory recursively, but the actual .sqlite file had somehow reverted to 644 and both owner and group were my user.
That may have just been due to me messing up a build script, but my point is - checking a second time is quicker than digging through SO questions.
Also worth noting, if you have some routes working, but others failing with a 500 error, check that you actually have at least 1 row of data in your tables. I would recommend creating seeders and running php artisan passport:install to generate some initial data.
事实证明,问题在于PDO SQLite 驱动程序要求,如果您要执行写入操作(INSERT、UPDATE、DELETE、DROP等),则数据库所在的文件夹必须具有写入权限,并且实际的数据库文件。
| 归档时间: |
|
| 查看次数: |
13059 次 |
| 最近记录: |