简体   繁体   English

数据类型设置默认值Laravel

[英]Data types set a default value Laravel

What is the correct syntax for declaring a default value on creating a column in laravel? 在laravel中创建列时声明默认值的正确语法是什么? I tried this but I get many errors. 我试过了,但是出现很多错误。 Can someone help me to find out what is the problem here? 有人可以帮我找出问题所在吗?

在此处输入图片说明

This is the expected output of the table 这是表的预期输出 在此处输入图片说明

  Schema::create('tbl_payroll_leave_schedulev2', function (Blueprint $table) {
                $table->increments('payroll_leave_schedule_id');
                $table->integer('payroll_leave_employee_id')->unsigned();
                $table->foreign("payroll_leave_employee_id")->references("payroll_leave_employee_id")->on("tbl_payroll_leave_employee_v2")->onDelete('cascade');
                $table->date('payroll_schedule_leave');
                $table->integer('shop_id');
                $table->time('leave_hours')->default(DB::raw('NOT NULL DEFAULT 00:00'));
                $table->tinyInteger('leave_whole_day')->default('1');
                $table->decimal('consume', 4, 2)->default('0.00');
                $table->string('notes',255);

You cannot set the NOT NULL with the default function. 您不能使用default功能设置NOT NULL Columns are non nullable by default. 默认情况下,列不可为空。 The correct syntax for the leave_hours column would be like this: leave_hours列的正确语法如下:

$table->time('leave_hours')->default('00:00');

Try to change line in your config/database.php file 尝试更改config / database.php文件中的行

'strict' => true to 'strict' => false 'strict' => true'strict' => false

OR use useCurrent() 或使用useCurrent()

$table->time('leave_hours')->useCurrent();

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM