Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel Migration Error

Tags:

laravel-5.3

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');                      
    });
}
like image 482
Eden WebStudio Avatar asked Jan 07 '17 14:01

Eden WebStudio


People also ask

What is migration in Laravel 8?

What is Laravel Migration? Laravel Migration is an essential feature in Laravel that allows you to create a table in your database. It allows you to modify and share the application's database schema. You can modify the table by adding a new column or deleting an existing column.

What is migrate command in Laravel?

Migrations are like version control for your database, allowing a team to easily modify and share the application's database schema. Migrations are typically paired with Laravel's schema builder to easily build your application's database schema.

What is migration squashing in Laravel?

Migration SquashingLaravel will write the new schema file to database/schema . Then when you run your migrations, Laravel will run the SQL from the schema file first before moving on to anything created later in the migrations folder. Note: Migration squashing is currently only supported for MySQL and Postgres.

Where is migration file in Laravel?

The migration will be placed in your app/database/migrations folder, and will contain a timestamp which allows the framework to determine the order of the migrations.


1 Answers

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

like image 200
Hamid Haghdoost Avatar answered Sep 28 '22 00:09

Hamid Haghdoost