0

I am attempting to run a migration but the following error is showing up:

{"error":{"type":"Symfony\Component\Debug\Exception\FatalErrorException","message":"Call to a member function increments() on a non-object","file":"/Applications/MAMP/htdocs/khadamat/app/database/migrations/2014_03_17_165445_create-users-table.php","line":16}}{"error":{"type":"Symfony\Component\Debug\Exception\FatalErrorException","message":"Call to a member function increments() on a non-object","file":"/Applications/MAMP/htdocs/khadamat/app/database/migrations/2014_03_17_165445_create-users-table.php","line":16}}

This is the code including line 16:

class CreateUsersTable extends Migration {

    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {

        $table->increments('id');
        $table->string('firstname', 40);
        $table->string('lastname', 40);
        $table->string('dob', 40);
        $table->string('email', 150)->unique();
        $table->string('password', 64);
        $table->string('address', 200);
        $table->string('city', 40);
        $table->string('country', 100);
        $table->string('register_purpose', 40);
        $table->timestamps();

    }

any clear reason as to why this is happening? Thanks in advance

1
  • You're referring to something that doesn't exist called $table in your function. Remember that when making schema changes, you need to use Schema::create()/Schema::table() and do your work inside the closure you pass in. Commented Mar 17, 2014 at 17:15

1 Answer 1

2

Better use artisan tool to generate migration... creating-migrations.. Some code from my projects migration table...

<?php

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

class CreateVideosTable extends Migration {

/**
 * Run the migrations.
 *
 * @return void
 */
public function up()
{
    Schema::create('videos', function(Blueprint $table) {
        $table->increments('id');
        $table->string('title');
        $table->text('description');
        $table->string('image');
        $table->text('embed');
        $table->timestamps();
    });
}


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

}
Sign up to request clarification or add additional context in comments.

1 Comment

Yup was missing Schema::create('videos', function(Blueprint $table). Thanks :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.