2017-01-07 213 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();