1

I created a new model and associated migration but I haven't created any instances of this model. My development server runs fine but when I run my tests every test fails with the following error:

DRb::DRbRemoteError: PG::NotNullViolation: ERROR: null value in column "some_value" of relation "table_name" violates not-null constraint

some_value is a non-null column but I haven't set a default because there isn't a sensible default and I want the field to be properly provided any time a record is created. Given that I haven't created any records and I am not running any test code using this model yet, what is causing the issue?

1 Answer 1

1

I hadn't manually created any instances of this model, but as usual, Rails creates fixtures for each new model including some dummy data. In this case, the non-null column was provided a value (Rails defaults to MyString), however this field is an enum, so the string doesn't store to the database (where an enum is represented as an integer) so it comes through as null. The issue only occurs in test (and occurs in every test) because fixtures are loaded for each test into the database).

The solution is simple: Provide a valid enum value or remove unneeded fixtures!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.