> For the complete documentation index, see [llms.txt](https://ploegert.gitbook.io/til/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ploegert.gitbook.io/til/programmy/rails/skip-validations-when-creating-a-record.md).

# Skip Validations When Creating A Record

Validations on your [ActiveRecord](https://api.rubyonrails.org/classes/ActiveRecord/Base.html) models are there for a reason. They provide application-level feedback about data that doesn't meet business requirements. In many cases those validations should also be pushed down to the database-layer in the form of constraints.

Sometimes, though rarely and probably only in a testing or development context, you'll want to skip validations.

This is how you can do that when creating a new record:

```ruby
user = User.new(
  name: 'Josh',
  email: '',
  password: SecureRandom.uuid
)

user.valid?
#=> false
user.errors.messages
#=> {:email=>["can't be blank"]}

user.save(validate: false)
```

After newing-up an object with invalid data, you can [save it with the `validate` option set to `false`](https://api.rubyonrails.org/classes/ActiveRecord/Persistence.html#method-i-save). This will skip ActiveRecord validations.

Note: If you also have a database-layer constraint, this won't work. Perhaps for your use case you can get by with a new non-persisted record.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://ploegert.gitbook.io/til/programmy/rails/skip-validations-when-creating-a-record.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
