2017-01-07 212 views
3

我似乎無法找出爲什麼我在這個遷移文件收到此錯誤?Laravel遷移錯誤

錯誤

[37;41米[Symfony的\元器件\調試\異常\ FatalThrowableError]←[39;49米 ←[37;41米調用一個成員函數可爲空的()上的空←[39 ; 49m

該文件的日期是在Customers表中創建外部id後。這是laravel 5.3。我該如何解決這個錯誤?

public function up() 
{ 
    Schema::create('invoices', function (Blueprint $table) { 
     $table->increments('id'); 
     $table->timestamps();   
     $table->integer('customer_id')->unsigned(); 
     $table->timestamps('date_from')->nullable(); 
     $table->timestamps('date_to')->nullable(); 
     $table->date('invoice_date')->nullable(); 
     $table->date('due_at')->nullable();  
     $table->integer('total_charge')->nullable(); 
     $table->integer('rate')->nullable(); 
     $table->integer('total_hours')->nullable(); 
     $table->string('status')->nullable(); 
     $table->string('description', 255)->nullable(); 
     $table->string('notes', 255)->nullable(); 
     $table->string('invoice_ref')->nullable(); 

     $table->foreign('customer_id') 
       ->references('id')->on('customers') 
       ->onDelete('cascade');      
    }); 
} 

回答

3

使用timestamp方法在這兩條線...

$table->timestamp('date_from')->nullable(); 
$table->timestamp('date_to')->nullable(); 

timestamps()不接受任何參數,並創建兩個colums:created_atupdated_atHere

4

從刪除這兩條線的代碼

$table->timestamp('date_from')->nullable(); 
$table->timestamp('date_to')->nullable(); 

並且只包括此線用於timpstamping:

$table->timestamps();