Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Not null violation: 7 ERROR: null value in column – Laravel 5.8

I don’t understand this, I alter my table to add these columns

Schema::table('clusters', function($table)
{

    $table->string('ssaEnabled',1)->default('0');
    $table->string('ssaBackendUrl')->default(NULL);
    $table->string('ssaPortalApiUrl')->default(NULL);

});

in my store() I have this

$cluster->ssaEnabled            = Input::get('ssaEnabled','0');
$cluster->ssaBackendUrl         = Input::get('ssaBackendUrl','');
$cluster->ssaPortalApiUrl       = Input::get('ssaPortalApiUrl','');

$cluster->save();

I kept getting

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

prod.ERROR: SQLSTATE[23502]: Not null violation: 7 ERROR: null value in column "ssaBackendUrl" violates not-null constraint

Why ??

  1. I set it to default null already
  2. I also add a backup value in my Input::get() in the 2nd param as an empty string

Any hints?

How can I stop that ?

>Solution :

  • Create a new migration

php artisan make:migration add_nullable_to_ssaBackendUrl_column_on_clusters_table --table=clusters

Updating Column Attributes

The change method allows you to modify the type and attributes of
existing columns.


Schema::table('clusters', function($table)
{

    $table->string('ssaBackendUrl')->nullable()->change();

});
  • Run the migration

php artisan migrate

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading