Laravel + SQLite = SQLSTATE[HY000]General Error: 8 尝试写入只读数据库
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/47835714/
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
Laravel + SQLite = SQLSTATE[HY000]General Error: 8 attempt to write a readonly database
提问by Miguelopezv
I'm trying to delete a db.sqlite file, create it again and then insert some info on this DB all in the same method, this is the method I'm using:
我正在尝试删除一个 db.sqlite 文件,再次创建它,然后以相同的方法在此数据库上插入一些信息,这是我正在使用的方法:
public function destroy()
{
// Store all contents and delete the first one since this is created via seeder
$contents = $this->contents->all()->toArray();
array_shift($contents);
// Delete db file, creates it from an example file and changes permissions
system('rm -rf ../database/database.sqlite');
system('cp ../database/database.sqlite.example ../database/database.sqlite');
system('chmod 0777 ../database/');
system('chmod 0777 ../database/database.sqlite');
// Insert data
foreach ($contents as $content) {
$this->contents->create($content);
}
return response()->json(['message' => 'Data has been destroyed!']);
}
However when I try to run it i get the error described on the title:
但是,当我尝试运行它时,出现标题中描述的错误:
SQLSTATE[HY000]General Error: 8 attempt to write a readonly database
SQLSTATE[HY000]General Error: 8 attempt to write a readonly database
I'm giving 777 permissions to the file and the folderas recommended on others questions answers, so I have no idea why it isn't working.
我按照其他问题答案的建议为文件和文件夹授予 777 权限,所以我不知道为什么它不起作用。
采纳答案by Miguelopezv
Finally I solved it by using to different methods, one to delete the DB and create again (returning all the contents) and then, the second one to insert all the contents to the new DB.
最后我通过使用不同的方法解决了它,一种是删除数据库并重新创建(返回所有内容),然后是第二种将所有内容插入到新数据库中。
回答by Hamza Zymawy
You need to run two commands
你需要运行两个命令
First, change ownership of the Laravel directory to web group:
首先,将 Laravel 目录的所有权更改为 web 组:
sudo chown -R :www-data /var/www/yourLarvelFolder
sudo chown -R :www-data /var/www/yourLarvelFolder
Second, give privileges over storage directory so it can be writable:
其次,赋予存储目录权限,使其可写:
sudo chmod -R 775 /var/www/yourLarvelFolder/storage
sudo chmod -R 775 /var/www/yourLarvelFolder/storage
回答by Jignesh Joisar
give permission here in ubuntu working on 18.04and laravel 6
在 ubuntu 18.04和 laravel 6上给予许可
sudo chmod -R 775 database
sudo chown -R $(whoami) database
回答by giuseppe
If you are on Fedora or Redhat with Selinux rememebr to switch off Selinux (or configure it correctly):
如果您在 Fedora 或 Redhat 上使用 Selinux rememebr 关闭 Selinux(或正确配置):
setenforce 0
回答by Hamfri
First run the following command to check apache2's user. Usually it is www-data
首先运行以下命令查看apache2的用户。通常是www-data
ps aux | grep "apache2"
Then run the following commands to resolve your issue.
然后运行以下命令来解决您的问题。
chgrp -R www-data your_application_directory
chmod -R g+rw your_application_directory