我正试图删除一个数据库.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!']);
}
但是,当我try 运行它时,会出现标题中描述的错误:
SQLSTATE[HY000]General Error: 8 attempt to write a readonly database
100正如其他问题的答案所建议的,所以我不知道为什么它不起作用.