ActiveRecord::ReadOnlyRecord Ruby / Rails Origin: Application & API Last updated 5 Nov 2026

Rails: ActiveRecord::ReadOnlyRecord: Order is marked as readonly

You tried to save a record that was loaded as read-only (e.g. via joins in old Rails or readonly scope).

Exact message you may see ActiveRecord::ReadOnlyRecord: Order is marked as readonlyActiveRecord::ReadOnlyRecord (ActiveRecord::ReadOnlyRecord)readonly attribute updated ActiveRecord
Seen on: Ruby

Meaning

Records loaded with readonly or .readonly(true) can't be saved. In Rails < 4 joins implied readonly; use includes/select. Check readonly?, attr_readonly, and self.readonly? overrides (e.g. database views). Reload the record via Order.find(id) for writes.

Common causes

  • .readonly scope applied
  • Model backed by a view with readonly? true
  • attr_readonly attribute updated
  • Records from joins/select custom queries
  • ReadOnlyRecord override

⚡ Quick fix

  1. Order.find(order.id).update!(...) to get a writable copy
  2. Remove .readonly or override readonly?
  3. Don't update attr_readonly columns

Detailed fix by platform

Rails

  1. order.readonly? # => true

How to diagnose

  1. Source — readonly scope?
  2. Model — View-backed?
  3. Column — attr_readonly?

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

Where this error sits

Origin: Application & API. Errors that are often confused with or caused by this one (click to open):

ActiveRecord::AssociationTypeMismatch — Rails: ActiveRecord::AssociationTypeMismatch: User(#1234) expected, got "42" which is an instance of String(#5678) (Ruby / Rails)ActiveRecord::Associa…ActiveRecord::ConnectionNotEstablished — Rails: ActiveRecord::ConnectionNotEstablished: No connection pool for 'ActiveRecord::Base' found (Ruby / Rails)ActiveRecord::Connect…ActiveRecord::Deadlocked: PG::TRDeadlockDetected — Rails: ActiveRecord::Deadlocked: PG::TRDeadlockDetected: ERROR: deadlock detected (Ruby / Rails)ActiveRecord::Deadloc…ActiveRecord::RecordInvalid: Validation failed — Rails: ActiveRecord::RecordInvalid: Validation failed: Email can't be blank, Name is too short (Ruby / Rails)ActiveRecord::RecordI…ActiveRecord::StaleObjectError (optimistic locking) — Rails: ActiveRecord::StaleObjectError: Attempted to update a stale object: Order (Ruby / Rails)ActiveRecord::StaleOb…PG::ConnectionBad: could not connect to server — Rails: PG::ConnectionBad: could not connect to server: Connection refused. Is the server running on host "localhost" (127.0.0.1) and accepting TCP/IP connections on port 5432? (Ruby / Rails)PG::ConnectionBad: co…PG::UndefinedTable: relation does not exist — Rails: ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR: relation "users" does not exist (Ruby / Rails)PG::UndefinedTable: r…ActiveRec…

Explore the map of this error Full error map →

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.

💬 What worked for others

No tips yet — did something else fix this for you?

Share what worked for you

Tips are checked by an editor before they appear. Links are removed.