Rails 4 SQLite3::ReadOnlyException: 尝试写入只读数据库

Rails 4 SQLite3::ReadOnlyException: attempt to write a readonly database

我在尝试登录我的 Rails 4 应用程序时一直收到错误 SQLite3::ReadOnlyException: attempt to write a readonly database: UPDATE "users" SET "current_sign_in_at" = ?, "sign_in_count" = ?, "updated_at" = ? WHERE "users"."id" = ?,该应用程序使用 gem.

我认为它与开发数据库的权限有关,所以首先检查了目录的权限,它有一个 + 附加在最后,经过一些谷歌搜索仍然无法弄清楚它在做什么。

-rw-r--r--   1 a36971  staff   2.1K 24 Jan 20:16 Gemfile
-rw-r--r--   1 a36971  staff   5.7K 24 Jan 20:16 Gemfile.lock
-rw-r--r--   1 a36971  staff    47B  7 Jan 22:31 README.md
-rw-r--r--+  1 root    staff   249B  7 Jan 19:57 Rakefile
drwxr-xr-x+  8 root    staff   272B  7 Jan 19:57 app/
drwxr-xr-x+  7 root    staff   238B  7 Jan 19:57 bin/
drwxr-xr-x+ 13 root    staff   442B 22 Jan 20:14 config/
-rw-r--r--+  1 root    staff   153B  7 Jan 19:57 config.ru
drwxr-xr-x+  8 root    staff   272B 26 Jan 10:28 db/
drwxr-xr-x+  4 root    staff   136B  7 Jan 19:57 lib/
drwxr-xr-x+  5 root    staff   170B  8 Jan 15:51 log/
drwxr-xr-x+  7 root    staff   238B  7 Jan 19:57 public/
drwxr-xr-x   7 a36971  staff   238B 17 Jan 22:38 spec/
drwxr-xr-x+  9 root    staff   306B  7 Jan 19:57 test/
drwxr-xr-x+  6 root    staff   204B  7 Jan 20:19 tmp/
drwxr-xr-x+  3 root    staff   102B  7 Jan 19:57 vendor/

cd 进入数据库目录后,您可以看到数据库本身的权限没有任何问题:

-rw-r--r--  1 a36971  staff    44K 26 Jan 09:30 development.sqlite3
drwxr-xr-x  5 a36971  staff   170B 22 Jan 20:14 migrate/
-rw-r--r--  1 a36971  staff   2.2K 22 Jan 20:14 schema.rb
-rw-r--r--  1 a36971  staff   1.2K 25 Jan 23:22 seeds.rb
-rw-r--r--  1 a36971  staff    44K 26 Jan 09:23 test.sqlite3

所以我的问题是:

a) 为什么在权限本身似乎没有任何问题的情况下无法写入数据库

b) + 在 mac os 上是什么意思?

a) why is it unable to write to the db when there doesn't appear to be anything wrong with the permissions themselves

我最好的猜测是 db/ 目录归 root 用户所有,而 db/*.sqlite3 文件归用户 a36971 所有。可能需要 db/ 目录也由用户 a36971.

拥有

尝试将 db 目录的所有者从 root 更改为 a36971

sudo chown a36971 db

b) what does the + mean on mac os?

+ 符号表示 ls -l 的默认输出未显示其他权限详细信息。尝试 运行 ls -le 查看详细信息(来源:http://tech.enekochan.com/en/2014/05/29/plus-and-at-symbols-listing-file-permissions-in-mac-os-x/)。

在 运行 rails db:reset

之后出现同样的错误

重启本地服务器解决了我的问题