Rails 3.1:Sqlite异常 [英] Rails 3.1: Sqlite exception

查看:111
本文介绍了Rails 3.1:Sqlite异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在VDS上启动非常简单的Ruby on Rails应用程序。我使用Nginx,Phusion Passenger和Sqlite3。我拥有root权限。



创建项目的代码:

  $ rails new myapplication 
$ cd / rails_apps / myapplication
$ bundle install
$ rails generate scaffold文件名:string title:string content:text
$ RAILS_ENV = production rake db:migrate

我可以访问主页,显示确定。但是当我尝试插入数据到DB,我得到下一个:

  SQLite3 :: ReadOnlyException:试图写一个只读数据库:INSERT INTOposts(content,created_at,name,title,updated_at)VALUES(?,?,?,?,?)
pre>

如何解决这个问题?



UPD:


$ b b

  chmod 777 \db 

解决方案

听起来像是一个特权问题。确保您运行rails的用户具有编辑文件的权限。例如,如果你在phusion下运行rails,我相信rails有效的用户和组是nginx运行的用户和组。测试是否是权限。我将从你的sqlite数据库文件的 chmod 777 开始,看看是否有帮助。如果是这样,请继续查看是否可以更合理地设置权限和db文件的所有权给您的nginx用户。


I try to launch really simple Ruby on Rails app on VDS. I use Nginx, Phusion Passenger and Sqlite3. I have root rights.

Code of creating project:

$ rails new myapplication
$ cd /rails_apps/myapplication
$ bundle install
$ rails generate scaffold Post name:string title:string content:text
$ RAILS_ENV=production rake db:migrate

I can visit main page, it shows ok. But when i try insert data into DB, i get next:

SQLite3::ReadOnlyException: attempt to write a readonly database: INSERT INTO "posts" ("content", "created_at", "name", "title", "updated_at") VALUES (?, ?, ?, ?, ?)

How can i fix that?

UPD:

chmod 777 \db

Helped me.

解决方案

Still sounds like a privileges issue to me. Make sure that the user that you're running rails as has permission to edit the file. For instance, if you're running rails under phusion, I believe that the rails effective user and group are the user and group that nginx runs as. To test if it is permissions. I would start with chmod 777 on your sqlite db file, and see if that helps. If so, follow up to see if you can set the permissions more reasonably and ownership of the db file to your nginx user.

这篇关于Rails 3.1:Sqlite异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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