Laravel + SQLite = SQLSTATE [HY000]常规错误:8次尝试编写只读数据库 [英] Laravel + SQLite = SQLSTATE[HY000]General Error: 8 attempt to write a readonly database

查看:54
本文介绍了Laravel + SQLite = SQLSTATE [HY000]常规错误:8次尝试编写只读数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试删除db.sqlite文件,再次创建它,然后使用相同的方法将一些信息全部插入此DB中.这是我正在使用的方法:

I'm trying to delete a db.sqlite file, create it again and then insert some info into this DB all in the same method. This is the method I'm using:

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 in the title:

SQLSTATE [HY000]常规错误:8次尝试写入只读数据库

我正在设置文件和文件夹的777权限 ,这是其他人的问题的答案所建议的,所以我不知道为什么它不起作用.

I'm setting 777 permissions on the file and the folder as recommended by others questions' answers, so I have no idea why it isn't working.

推荐答案

最后,我通过使用不同的方法解决了这个问题,一种方法是删除数据库并再次创建(返回所有内容),然后第二种方法插入所有内容内容添加到新数据库中.

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.

这篇关于Laravel + SQLite = SQLSTATE [HY000]常规错误:8次尝试编写只读数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆