---
title: "ArgumentError for invalid :limit & :precision Rails 6"
description: "Rails 6 raises ArgumentError for invalid:limit and:precision"
canonical_url: "https://www.bigbinary.com/blog/rails-6-raises-argumenterror-for-invalid-limit-and-precision"
markdown_url: "https://www.bigbinary.com/blog/rails-6-raises-argumenterror-for-invalid-limit-and-precision.md"
---

# ArgumentError for invalid :limit & :precision Rails 6

Rails 6 raises ArgumentError for invalid:limit and:precision

- Author: Amit Choudhary
- Published: August 27, 2019
- Categories: Rails 6, Rails

Rails 6 raises [ArgumentError](https://apidock.com/ruby/ArgumentError) when
`:limit` and `:precision` are used with invalid datatypes.

Before Rails 6, it used to return
[ActiveRecord::ActiveRecordError](https://api.rubyonrails.org/classes/ActiveRecord/ActiveRecordError.html).

Let's checkout how it works.

#### Rails 5.2

Let's create an orders table and try using `:limit` with a column named as
quantity with data type `integer`.

```ruby

> > class CreateOrders < ActiveRecord::Migration[5.2]
> > def change
> > create_table :orders do |t|
> > t.string :item
> > t.integer :quantity, limit: 10
> >
> >       t.timestamps
> >     end
> >
> > end
> > end

=> :change

> > CreateOrders.new.change
> > -- create_table(:orders)

=> Traceback (most recent call last):
2: from (irb):11
1: from (irb):3:in 'change'
ActiveRecord::ActiveRecordError (No integer type has byte size 10. Use a numeric with scale 0 instead.)
```

We can see that use of `:limit` with `integer` column raises
[ActiveRecord::ActiveRecordError](https://api.rubyonrails.org/classes/ActiveRecord/ActiveRecordError.html)
in `Rails 5.2`.

Now let's try using `:precision` of `10` with a `datetime` column.

```ruby

> > class CreateOrders < ActiveRecord::Migration[5.2]
> > def change
> > create_table :orders do |t|
> > t.string :item
> > t.integer :quantity
> > t.datetime :completed_at, precision: 10
> >
> >       t.timestamps
> >     end
> >
> > end
> > end

=> :change

> > CreateOrders.new.change
> > -- create_table(:orders)

=> Traceback (most recent call last):
2: from (irb):12
1: from (irb):3:in 'change'
ActiveRecord::ActiveRecordError (No timestamp type has precision of 10. The allowed range of precision is from 0 to 6)
```

We can see that invalid value of `:precision` with datetime column also raises
[ActiveRecord::ActiveRecordError](https://api.rubyonrails.org/classes/ActiveRecord/ActiveRecordError.html)
in `Rails 5.2`.

#### Rails 6.0.0.rc1

Let's create an orders table and try using `:limit` with a column named as
quantity with data type `integer` in Rails 6.

```ruby

> > class CreateOrders < ActiveRecord::Migration[6.0]
> > def change
> > create_table :orders do |t|
> > t.string :item
> > t.integer :quantity, limit: 10
> >
> >       t.timestamps
> >     end
> >
> > end
> > end

=> :change

> > CreateOrders.new.change
> > -- create_table(:orders)

=> Traceback (most recent call last):
2: from (irb):11
1: from (irb):3:in 'change'
ArgumentError (No integer type has byte size 10. Use a numeric with scale 0 instead.)
```

We can see that use of `:limit` with `integer` column raises
[ArgumentError](https://apidock.com/ruby/ArgumentError) in `Rails 6`.

Now let's try using `:precision` of `10` with a `datetime` column.

```ruby

> > class CreateOrders < ActiveRecord::Migration[6.0]
> > def change
> > create_table :orders do |t|
> > t.string :item
> > t.integer :quantity
> > t.datetime :completed_at, precision: 10
> >
> >       t.timestamps
> >     end
> >
> > end
> > end

=> :change

> > CreateOrders.new.change
> > -- create_table(:orders)

=> Traceback (most recent call last):
2: from (irb):12
1: from (irb):3:in 'change'
ArgumentError (No timestamp type has precision of 10. The allowed range of precision is from 0 to 6)
```

We can see that invalid value of `:precision` with datetime column also raises
[ArgumentError](https://apidock.com/ruby/ArgumentError) in `Rails 6`.

Here is the relevant [pull request](https://github.com/rails/rails/pull/35887).

## Links

- [Human page](https://www.bigbinary.com/blog/rails-6-raises-argumenterror-for-invalid-limit-and-precision)
