PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, January 5, 2022

[FIXED] Not null violation: 7 ERROR: null value in column - Laravel 5.8

 January 05, 2022     database-migration, input, laravel, laravel-5, laravel-5.8     No comments   

Issue

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

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



Answered By - steven7mwesigwa
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing