# READONLY error

```json metadata
{
  "schema_version": 2,
  "title": "READONLY error",
  "description": "A command that changes data was sent to a read-only replica.",
  "categories": ["docs","develop","stack","oss","rs","rc","oss","kubernetes","clients"],
  "tableOfContents": {"sections":[{"id":"example","title":"Example"},{"id":"how-to-fix-it","title":"How to fix it"}]}

,
  "codeExamples": []
}
```


Redis returns this error when you send a command that changes data to a replica. A replica keeps a copy of a primary's data, and by default it's read-only. Only the primary accepts writes.

```
READONLY You can't write against a read only replica.
```

In redis-py, this error is `ReadOnlyError: You can't write against a read only replica.`

A Lua function, or a script that starts with a `#!lua` line, gets the same error on a replica before it starts, unless it has the `no-writes` flag. A script without that line gets the error when it calls a command that changes data, with the script's details added to the end.

## Example

```
> SET mykey "value"
(error) READONLY You can't write against a read only replica.
> GET mykey
"value"
```

## How to fix it

Check which node you're connected to with [`ROLE`](https://redis.io/docs/latest/commands/role). A replica replies with `slave` as the first item.

- **You meant to connect to the primary.** Check the host and port in your app's configuration.
- **The primary changed.** After a failover, a replica becomes the new primary, and the old primary can come back as a replica. An app that connects to a fixed address then ends up on a replica. Use a client that finds the current primary for you, through [Redis Sentinel](https://redis.io/docs/latest/operate/oss_and_stack/management/sentinel).

Don't make the replica writable to work around this error. The `replica-read-only no` setting exists for historical reasons, and writes to a replica can make its data differ from the primary's. See [Read-only replica](https://redis.io/docs/latest/operate/oss_and_stack/management/replication#read-only-replica).

