我正在尝试删除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!']);
}
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试运行它时,我得到标题上描述的错误:
SQLSTATE[HY000]General Error: 8 attempt to write a readonly database
我给了文件的777权限和其他问题答案推荐的文件夹 …