← Back to Upcase

Refactoring - PG not null violation error!

(Nikhil Chikorde) #1

I started making modifications to the code to organize the text shout and photo shout in shouts helper.
However, I am adding a text “text” and shout but it gives me below error. I am unable to figure out why i cant add “text” and shout. I can added any long text but not text. Clearly it says something null, but dont’ know what’s that… Help please!

ActiveRecord::NotNullViolation in ShoutsController#create
PG::NotNullViolation: ERROR: null value in column “content_id” violates not-null constraint DETAIL: Failing row contains (19, 2, 2019-02-25 23:47:54.05042, 2019-02-25 23:47:54.05042, TextShout, null). : INSERT INTO “shouts” (“user_id”, “created_at”, “updated_at”, “content_type”) VALUES ($1, $2, $3, $4) RETURNING “id”

(Cire DIA) #2

It says that content_id should not be null. If u have an association to a content table verify that the associated model should exist before the creation of shout.