Why this ERROR: General error: 1364 Field 'user_id' doesn't have a default value

general error 1364 field doesn't have a default value laravel
sql error: 1364, sqlstate: hy000 hibernate
mysql error sqlstate hy000: general error: 1364 field perms doesn t have a default value
mysql sqlstate hy000 general error 1364
pdoexception sqlstate(hy000): general error: 1364
field fullname doesn t have a default value
field image_id doesn t have a default value
mariadb field doesn't have a default value

i have postqs and users table. user_id is foreign key in postqs table . i have a form and after i submit the form all the data saving in database correctly. but it is not directing to index page its showing this ERROR:

SQLSTATE[HY000]: General error: 1364 Field 'user_id' doesn't have a default value (SQL: insert into Postqs (question, description, solution, image, tags, updated_at, created_at) values (hh, bb, bb, images .bmp.jpg, bb, 2017-09-20 08:14:32, 2017-09-20 08:14:32))

How i can solve it?

store controller function :

public function store(Request $request)
{
    $this->validate($request, [
        'question' => 'required',
        'description' => 'required',
        'tags' => 'required',

    ]);

    $user = auth()->user();
    $user->postqs()->create($request->all() );

    $input = $request->all();
    $tags = explode(",", $request->tags);

    $postqs = Postqs::create($input);
    $postqs->tag($tags);

    return redirect()->route('postqs.index')
                    ->with('success','Your question created successfully');

index controller function:

   $postqs=Postqs::whereHas('user')->get();        
    return view('postqs.index',compact('postqs','users'));

postqs model:

    protected $fillable = 
    ['question','description','solution','image','tags','user_id'];

    public function user(){
    return $this->belongsTo("App\User"); }

User model:

    public function postqs(){
     return $this->hasMany("App\Postqs");
    }

the field user_id in your table is not nullable, and you tried to save post without user_id, or may be user_id is not passed by request. Try this:

$this->validate($request, [
    'question' => 'required',
    'description' => 'required',
    'tags' => 'required',

]);

$user = auth()->user();
$data = $request->all();
$data['user_id']=$user->id;
$user->postqs()->create($data);
$tags = explode(",", $request->tags);

$postqs = Postqs::create($data);
//$postqs->tag($tags);
$postqs->tag()->save($tags);

return redirect()->route('postqs.index')
                ->with('success','Your question created successfully');

Why this ERROR: General error: 1364 Field 'user_id' doesn't have a , the field user_id in your table is not nullable, and you tried to save post without user_id, or may be user_id is not passed by request. Try this: The general error 1364 is basically triggered when you are try to insert/update a record on your database where a field, namely the one that is triggering the exception cannot be null, however you are trying to set its value as null (you are not providing a value for it).


you did not post your table's schema, but from the error it seems that you have a field user_id which is set as non-null and does not have a default value- which means every insert query must provide its value.

The solution - either give the column a default value, or pass it in your query

General error: 1364 Field 'field_name' doesn't , How to solve MySQL exception SQLSTATE[HY000]: General error: 1364 Field '​field_name' doesn't have a default value. June 5th 2018; 33.3K; 1 Comment. Seeding: LaratrustSeeder Truncating User, Role and Permission tables Creating Role SUPERADMINISTRATOR Creating Permission to create for users Creating Permission to read for users Creating Permissi


When i had this error, this was my solution from @Matius's answer

$user = auth()->user();
$data = $request->all();
$data['user_id']=$user->id;

SQLSTATE[HY000]: General error: 1364 Field 'last_name' doesn't , SQLSTATE[HY000]: General error: 1364 Field 'last_name' doesn't have a default value. Posted 3 years ago by basosneo. I am doing a  So I have, table courses: CREATE TABLE IF NOT EXISTS `AppDziennik`.`courses` ( `id_course` INT NOT NULL AUTO_INCREMENT , `name` VARCHAR(80) NOT NULL , `teachers_id_teacher` INT NOT NULL , `


Did you add a user to your database? Please add a user and then you must add user_id to $fillable.

[BUG] General error: 1364 Field 'name' doesn't have a default value , [BUG] General error: 1364 Field 'name' doesn't have a default value #38. Closed. gabrielchavezme opened this issue on Dec 28, 2019 · 1 comment. Closed  General error: 1364 Field 'id' doesn't have a default value: INSERT INTO {field_group} I'm having the following error when trying to add some Field Group to Commerce Order Settings: PDOException: SQLSTATE[HY000]: General error: 1364 Field 'id' doesn't have a default value: INSERT INTO { field_group } ( identifier, group_name, entity_type, bundle, mode, parent_name, data) VALUES (: db_insert_placeholder_0, : db_insert_placeholder_1, : db_insert_placeholder_2, : db_insert_placeholder_3, :


In my case, after a Mysql update, the indexes of the database were gone. I was getting the same error messages that we are talking about.

I had to recreate the indexes and make the id column on each table the primary key, and auto-increment.

After that... Everything, works.

General error: 1364 Field 'username' doesn't have a default value , General error: 1364 Field 'username' doesn't have a default value (username auth) #729. Closed. jeremiahsherrill opened this issue on May 7,  General error: 1364 Field 'department_id' doesn't have a default value Hot Network Questions What is the context of this seemingly "zero-gravity" photo on Earth?


There was a problem creating field: SQLSTATE[HY000]: General , However, after a few tests, I've found a bug: the add new field feature is field Comments: SQLSTATE[HY000]: General error: 1364 Field 'id'  General error: 1364 Field 'created' doesn't have a default value' in \lib\Zend\Db\Statement\Pdo.php:238. Ask Question Asked 8 years, 9 months ago.


Error 1364, field 'last_login' doesn't have a default value, I receive the following error message: Error - SQLSTATE[HY000]: General error: 1364 Field 'last_login' doesn't have a d efault value with query: "INSERT INTO  This is caused by MySQL having a strict mode set which won't allow INSERT or UPDATE commands with empty fields where the schema doesn't have a default value set. There are a couple of fixes for this. First 'fix' is to assign a default value to your schema. This can be done with a simple ALTER command:


SQLSTATE[HY000]: General error: 1364 Field 'file' doesn't have a , upload form was working fine but now I get a SQLSTATE[HY000]: General error: 1364 Field 'file' doesn't have a default value". PDOException: SQLSTATE[HY000]: General error: 1364 Field 'item_id' doesn't have a default value for MANY, MANY fields, and tables, not just the one in this specific message. The specifics vary depending on the operation I am trying to perform.