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

Wednesday, April 13, 2022

[FIXED] How i define a default value?

 April 13, 2022     laravel, migration, php     No comments   

Issue

How to fix this?

SQLSTATE[HY000]: General error: 1364 Field 'note' doesn't have a default value (SQL: insert into people (name, email, user_id, updated_at, created_at) values (Luis, luis@hotmail.com, 2, 2021-08-09 15:03:07, 2021-08-09 15:03:07))

My migration:

I've already tried to set a default value, but I believe I'm not doing it right


Solution

You should either decide to have a default null value or some default other string.

For default null value:

Schema::table('people', function (Blueprint $table) {
    $table->longText('note')->nullable()->after('email');
});

Any other default value should be:

Schema::table('people', function (Blueprint $table) {
    $table->longText('note')->default('Some Default Value.')->after('email');
});


Answered By - Mohsen Nazari
Answer Checked By - Timothy Miller (PHPFixing Admin)
  • 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