TLDR version
My code expected the default value of attr_name
to be at least 0
, but due to certain circumstances, the default value of the attr_name
column in the database table was null. Which resulted in the error I mentioned above.
Detailed explaination
The schema of my development database was out of sync with my production database (due to a few migrations that did not went into production). So whenever I ran a rake db:migrate
, it created a schema.rb
based on out-of-sync development database's schema. And this schema was then used by rake db:test:prepare
, creating a database based on the outdated schema. Most importantly, the code had expected the value of attr_name
to be at least 0 value from attr_name
, but in the outdated schema, the attr_name
column was null by default.