简体   繁体   English

SQLSTATE [HY000]:一般错误:1364 字段“名称”在 laravel 中没有默认值

[英]SQLSTATE[HY000]: General error: 1364 Field 'name' doesn't have a default value in laravel

I'm using mysql v5.7 and laravel v5.8.我正在使用 mysql v5.7 和 laravel v5.8。 I made register function using by auth and when I try to register it's showing an error.我使用 auth 注册了 function ,当我尝试注册时显示错误。

SQLSTATE[HY000]: General error: 1364 Field 'name' doesn't have a default value (SQL: insert into users ( email , password , updated_at , created_at ) values (***@gmail.com, $2yd4GvC, 2020-05-25 19:53:37, 2020-05-25 19:53:37)) SQLSTATE [HY000]:一般错误:1364 字段“名称”没有默认值(SQL:插入usersemailpasswordupdated_atcreated_at )值(***@gmail.com,2yd4GvC,$2yd4Gv 05-25 19:53:37, 2020-05-25 19:53:37))

it's working fine in localhost but showing this error after adding it to ec2 server.它在 localhost 中工作正常,但在将其添加到 ec2 服务器后显示此错误。

I changed config/database.php我更改了 config/database.php

like this像这样

'strict' => false, '严格' => 假,

then i can register, but there is no value in name columns.然后我可以注册,但名称列中没有值。

enter image description here在此处输入图像描述

and can put other columns except for name column.并且可以放置除名称列之外的其他列。

I don't know why it's works on local server but showing error in live server.我不知道为什么它可以在本地服务器上运行,但在实时服务器中显示错误。

This is my code.这是我的代码。

User.php用户.php


class User extends Authenticatable
{
    use Notifiable;

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'name', 'email', 'password',
    ];

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'password', 'remember_token',
    ];

    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = [
        'email_verified_at' => 'datetime',
    ];
}



create_users_table.php create_users_table.php

    public function up()
    {
        Schema::create('users', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string('name');
            $table->string('email')->unique();
            $table->timestamp('email_verified_at')->nullable();
            $table->string('password');
            $table->rememberToken();
            $table->timestamps();
        });
    }

Can anybody help me?有谁能够帮我?

This query:这个查询:

INSERT INTO users (email, password, updated_at, created_at)
VALUES (***@gmail.com, $2yd4GvC, 2020-05-25 19:53:37, 2020-05-25 19:53:37)

does not insert the name field.不插入name字段。 When this field cannot be NULL MySQL will give an error.当该字段不能为 NULL MySQL 时会报错。

The reason why you don't get this error on your localhost is probably that the MySQL config is less strict.您在本地主机上没有收到此错误的原因可能是 MySQL 配置不那么严格。

Setting 'strict' => false, will remove the error, but your query still doesn't insert the name field values.设置'strict' => false,将删除错误,但您的查询仍然不会插入name字段值。

So the real solution is to keep your database config set to strict (because then you will notice errors much faster).所以真正的解决方案是将你的数据库配置设置为严格(因为这样你会更快地注意到错误)。 And then change your query so it will insert the name value.然后更改您的查询,使其插入name值。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 SQLSTATE[HY000]:一般错误:1364 字段“名称”没有默认值 laravel 5.5 - SQLSTATE[HY000]: General error: 1364 Field 'name' doesn't have a default value laravel 5.5 SQLSTATE [HY000]:常规错误:1364字段“照片”在laravel 5.5中没有默认值 - SQLSTATE[HY000]: General error: 1364 Field 'photo' doesn't have a default value in laravel 5.5 Laravel Voyager SQLSTATE [HY000]:常规错误:1364字段“ id”没有默认值 - Laravel Voyager SQLSTATE[HY000]: General error: 1364 Field 'id' doesn't have a default value Laravel SQLSTATE [HY000]:常规错误:1364字段“ id”没有默认值 - Laravel SQLSTATE[HY000]: General error: 1364 Field 'id' doesn't have a default value Laravel“SQLSTATE[HY000]:一般错误:1364 字段‘登录’没有默认值……” - Laravel "SQLSTATE[HY000]: General error: 1364 Field 'Login' doesn't have a default value..." Laravel 8:SQLSTATE[HY000]:一般错误:1364 字段“答案”没有默认值 - Laravel 8: SQLSTATE[HY000]: General error: 1364 Field 'answer' doesn't have a default value SQLSTATE [HY000]:常规错误:1364字段“ practice_name”没有默认值 - SQLSTATE[HY000]: General error: 1364 Field 'practice_name' doesn't have a default value SQLSTATE[HY000]:一般错误:1364 字段“contactId”没有默认值 - SQLSTATE[HY000]: General error: 1364 Field 'contactId' doesn't have a default value SQLSTATE [HY000]:常规错误:1364字段“性别”没有默认值 - SQLSTATE[HY000]: General error: 1364 Field 'gender' doesn't have a default value SQLSTATE [HY000]:常规错误:1364字段“ starting_balance”没有默认值 - SQLSTATE[HY000]: General error: 1364 Field 'starting_balance' doesn't have a default value
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM