2016-11-23 88 views
1

我做的laravel登记表,首先我创建迁移如何使默认值空在laravel

<?php 

use Illuminate\Support\Facades\Schema; 
use Illuminate\Database\Schema\Blueprint; 
use Illuminate\Database\Migrations\Migration; 

class CreateUsersTable extends Migration 
{ 
    /** 
    * Run the migrations. 
    * 
    * @return void 
    */ 
    public function up() 
    { 
     Schema::create('users', function (Blueprint $table) { 
      $table->increments('id'); 
      $table->string('name'); 
      $table->string('first_name'); 
      $table->string('last_name'); 
      $table->string('email')->unique(); 
      $table->string('password'); 
      $table->rememberToken(); 
      $table->timestamps(); 
     }); 
    } 

    /** 
    * Reverse the migrations. 
    * 
    * @return void 
    */ 
    public function down() 
    { 
     Schema::drop('users'); 
    } 
} 

我想先不FIRST_NAME和姓氏登记姓名,电子邮件地址和密码,但我当点击注册它给我错误,first_name和last_name没有默认值..所以如何使默认值为空,因为我想稍后更新该列。

+0

您是否回滚并再次运行迁移,或者是否是新的迁移以更改值?你也有哪些SQL版本? – jycr753

回答

3
$table->string('first_name')->default('DEFAULT'); 

编辑:如果默认值应该为空,则使其为空。

$table->string('first_name')->nullable(); 
+0

它给了我同样的错误,我已经尝试过,在 – Devmasta

+0

之前抱歉。当然,如果默认值应该为null,则必须将该列设为空值。 – LorenzSchaef

+0

什么也没有,再次同样的错误,我试过'默认(空)','nullable()','空值() - >默认(空)'和总是相同的.. – Devmasta