Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

maryan's avatar

SQLSTATE[23000]: Integrity constraint violation: 19 NOT NULL constraint failed: articles.article

Hi everyone, I'm very new to laravel, this is my first project and I need little help.

I'm getting this error but I'm not sure how to fix it.

SQLSTATE[23000]: Integrity constraint violation: 19 NOT NULL constraint failed: articles.article (SQL: insert into "articles" ("title", "text", "image", "user_id", "updated_at", "created_at") values (ojhoijjo, jhbihnohiiu, uploads/mNvpVbkzo9eaY8Y1lgyjtJuSQY2PYc1lOMr62xbA.jpeg, 1, 2020-04-30 23:32:12, 2020-04-30 23:32:12))

0 likes
3 replies
trevorpan's avatar
Level 15

I've run across this and usually fix it in your migration, in your case it looks like class CreateArticlesTable extends Migration

try adding:

        Schema::create('articles', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->text('article'); // this is the line you're likely missing - it's possible you've named 'text' in the migration but reference 'article' in a blade view, e.g. if that's the case you can rename 'text' to 'article'
... other columns, 

Give that a go ...

MichalOravec's avatar

There are some columns in the table which have not null constraint and you are inserting null value.

1 like
maryan's avatar

I found my mistake

public function store()
{
    $data2 = request()->validate([
        'title' => 'required',
        'text' => 'required', //I had text here
        'image' => ['required', 'image'],
    ]);

Thank you for the help!

2 likes

Please or to participate in this conversation.