SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Jul 2007
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy SQLite Database write access

    Hi,

    I am new to sqlite and ROR and facing some problem. I searched the internet and this forum for the answer but couldn't find a solution which I can directly relate to my problem.

    The problem is fairly simple,

    I created a database and a table. using:

    sqlite3 db/development.sqlite3
    CREATE TABLE stories (
    "id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
    "name" varchar(255) DEFAULT NULL,
    "link" varchar(255) DEFAULT NULL,
    "created_at" datetime DEFAULT NULL,
    "updated_at" datetime DEFAULT NULL
    );

    Then I created an object using:
    $ ruby script/console
    class Story < ActiveRecord::Base; end
    => nil
    >> story = Story.new
    => #<Story id: nil, name: nil, url: nil, created_at: nil, updated_at: nil>
    >> story.class
    => Story(id: integer, name: string, link: string, created_at: datetime, updated_at: datetime)

    Then I tried to save it but received the following error:

    > story.save
    ActiveRecord::StatementInvalid: SQLite3::SQLException: attempt to write a readonly database: INSERT INTO "stories" ("name", "updated_at", "link", "created_at") VALUES(NULL, '2010-01-13 10:15:10', NULL, '2010-01-13 10:15:10')
    from /Users/macharris/.gem/ruby/1.8/gems/activerecord-2.3.5/lib/active_record/connection_adapters/abstract_adapter.rb:219:in `log'
    from /Users/macharris/.gem/ruby/1.8/gems/activerecord-2.3.5/lib/active_record/connection_adapters/sqlite_adapter.rb:172:in `execute'
    from /Users/macharris/.gem/ruby/1.8/gems/activerecord-2.3.5/lib/active_record/connection_adapters/sqlite_adapter.rb:417:in `catch_schema_changes'
    from /Users/macharris/.gem/ruby/1.8/gems/activerecord-2.3.5/lib/active_record/connection_adapters/sqlite_adapter.rb:172:in `execute'
    from /Users/macharris/.gem/ruby/1.8/gems/activerecord-2.3.5/lib/active_record/connection_adapters/abstract/database_statements.rb:259:in `insert_sql'
    from /Users/macharris/.gem/ruby/1.8/gems/activerecord-2.3.5/lib/active_record/connection_adapters/sqlite_adapter.rb:186:in `insert_sql'
    from /Users/macharris/.gem/ruby/1.8/gems/activerecord-2.3.5/lib/active_record/connection_adapters/abstract/database_statements.rb:44:in `insert_without_query_dirty'
    from /Users/macharris/.gem/ruby/1.8/gems/activerecord-2.3.5/lib/active_record/connection_adapters/abstract/query_cache.rb:18:in `insert'
    from /Users/macharris/.gem/ruby/1.8/gems/activerecord-2.3.5/lib/active_record/base.rb:2908:in `create_without_timestamps'
    from /Users/macharris/.gem/ruby/1.8/gems/activerecord-2.3.5/lib/active_record/timestamp.rb:53:in `create_without_callbacks'
    from /Users/macharris/.gem/ruby/1.8/gems/activerecord-2.3.5/lib/active_record/callbacks.rb:266:in `create'
    from /Users/macharris/.gem/ruby/1.8/gems/activerecord-2.3.5/lib/active_record/base.rb:2874:in `create_or_update_without_callbacks'
    from /Users/macharris/.gem/ruby/1.8/gems/activerecord-2.3.5/lib/active_record/callbacks.rb:250:in `create_or_update'
    from /Users/macharris/.gem/ruby/1.8/gems/activerecord-2.3.5/lib/active_record/base.rb:2538:in `save_without_validation'
    from /Users/macharris/.gem/ruby/1.8/gems/activerecord-2.3.5/lib/active_record/validations.rb:1078:in `save_without_dirty'
    from /Users/macharris/.gem/ruby/1.8/gems/activerecord-2.3.5/lib/active_record/dirty.rb:79:in `save_without_transactions'
    from /Users/macharris/.gem/ruby/1.8/gems/activerecord-2.3.5/lib/active_record/transactions.rb:229:in `send'
    from /Users/macharris/.gem/ruby/1.8/gems/activerecord-2.3.5/lib/active_record/transactions.rb:229:in `with_transaction_returning_status'
    from /Users/macharris/.gem/ruby/1.8/gems/activerecord-2.3.5/lib/active_record/connection_adapters/abstract/database_statements.rb:136:in `transaction'
    from /Users/macharris/.gem/ruby/1.8/gems/activerecord-2.3.5/lib/active_record/transactions.rb:182:in `transaction'
    from /Users/macharris/.gem/ruby/1.8/gems/activerecord-2.3.5/lib/active_record/transactions.rb:228:in `with_transaction_returning_status'
    from /Users/macharris/.gem/ruby/1.8/gems/activerecord-2.3.5/lib/active_record/transactions.rb:196:in `save'
    from /Users/macharris/.gem/ruby/1.8/gems/activerecord-2.3.5/lib/active_record/transactions.rb:208:in `rollback_active_record_state!'
    from /Users/macharris/.gem/ruby/1.8/gems/activerecord-2.3.5/lib/active_record/transactions.rb:196:in `save'
    from (irb):28>>

    How would I set access rights to overcome the attempt to write a readonly database error.

    Regards,

    Bret

  2. #2
    SitePoint Wizard
    Join Date
    Jul 2003
    Location
    Kent
    Posts
    1,921
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    You may have to play with chmod to set the file to be writeable.

  3. #3
    SitePoint Member
    Join Date
    Jul 2007
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you Dr. John, I m feeling so stupid how I missed that... lol


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •