'Laravel Migration Error
I cant seem to work out why I am getting this error on this migration file?
Error
[37;41m [Symfony\Component\Debug\Exception\FatalThrowableError] ←[39;49m ←[37;41m Call to a member function nullable() on null ←[39;49m
The date on the file is after the foreign id creation in the Customers table.This is laravel 5.3. How can I resolve this error?
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');
});
}
Solution 1:[1]
Use timestamp
method in this two lines...
$table->timestamp('date_from')->nullable();
$table->timestamp('date_to')->nullable();
timestamps()
not accepts any argument and creates two colums : created_at
and updated_at
See Here
Solution 2:[2]
Remove these two lines from your code
$table->timestamp('date_from')->nullable();
$table->timestamp('date_to')->nullable();
And only include this line for the timpstamping:
$table->timestamps();
Solution 3:[3]
You replace it like this - remove the s
from timestamp:
$table->timestamp('date_from');
$table->timestamps('date_day');
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Hamid Haghdoost |
Solution 2 | Kalanka |
Solution 3 | Ethan |