Reputation: 4767
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.
Upvotes: 1
Views: 5764
Reputation: 3375
If you are logged in as anyone other than the admin, you can use rvmsudo rake db:migrate
which will prompt you for your admin password and allow access rights for the migration you are attempting.
Upvotes: 3
Reputation: 4210
I received this same error in Rails 4.1 after removing the impressionist gem from my app.
What I ended up doing to fix this:
Everything worked fine after that, although it was a huge pain trying to figure out the cause.
One thing I would recommend doing for sure is to check your users
and make sure there aren't duplicates.
Upvotes: 0
Reputation: 1104
I know this is an old question, but for others that find it as I did while searching, I'd suggest looking at Benjamin's answer to this question:
How should I set up permission for Rails app?
Specifically as regards the above answer, his first line: "You should definitely not use 0777 for your file permissions. This more easily exposes you to vulnerabilities."
I know Matt was just suggesting it as a debugging step, he was not suggesting leaving it that way in production, but the OP seems to have taken it that way.
Upvotes: 0
Reputation: 91
After altering owner & rights of db files I had to restart rails server to make things work.
Upvotes: 9
Reputation: 1803
Rails 2.3.5 I also got the same problem when i am trying to insert a record then i am getting the same error :
The problem was when i created a project the db/schema.rb has the owner is root. i am logged in with my current user [not the root]. after changing the owner in ubuntu of the file.
check the owner of the file first then change the owner
chown userName fileName
Upvotes: 0
Reputation: 10564
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.
Upvotes: 4