Bluesail20
Bluesail20

Reputation: 319

Laravel migration error

I created a new project and a new fresh schema, made a very simple setup with a Users table, and tried to run migrations, but the migrator is failing on the first table, which of course is the Users table. I had a lot of trouble with this before, detailed on my previous question, and I ended up literally starting over from scratch. I have a super simple setup and still migrator is failing. Is there a bug? Where can I find out about it? Should I report this as a bug? It's really a discouraging thing for people who are trying to adopt this platform to get stumped like this so early in the process. Should I just ditch migrations and create my tables with sql scripts and move along?

Here is the error I am getting, extremely similar to the one I detailed in that previous question:

"Class 'UsersTable' not found... in src\Illuminate\Database\Migrations\Migrator.php  line 297

Here is my migration file:

<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;

class CreateUsersTable extends Migration {

/**
 * Run the migrations.
 *
 * @return void
 */
public function up()
{
    // Creates the users table
    Schema::create('users', function(Blueprint $table)
    {
       // $table->engine = 'InnoDB';

        $table->increments('id');

        $table->string('username', 40)
            ->nullable()
            ->default(null);

        $table->string('email', 40)
            ->unique();

        $table->string('password', 64);

        $table->smallInteger('acct_type')
            ->unsigned()
            ->default(1);

        $table->string('confirmation_code');

        $table->boolean('confirmed')
            ->default(false);

        $table->timestamps();

        $table->softDeletes();

    });

}

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

}

Frustrated.

Upvotes: 0

Views: 2932

Answers (2)

minorgod
minorgod

Reputation: 692

Also, for anyone else having similar problems not solved by the previous solution, I've found that sometimes running

 php artisan dump-autoload

doesn't work and a

 composer update

solves the problem.

Upvotes: -1

J.T. Grimes
J.T. Grimes

Reputation: 4272

The problem is likely with your filename. Generating a migration with artisan produces filenames in the format year_month_day_time_class_name_separated_by_underscores.

The code Laravel uses to come up with the class name from the filename is

public function resolve($file)
{
    $file = implode('_', array_slice(explode('_', $file), 4));

    $class = studly_case($file);

    return new $class;
}

That array_slice(...,4) bit means that Laravel requires that file names have four underscore-separated chunks at the beginning that can be thrown away and that the rest of the filename be the snake-case class name.

Not my first choice for how to do it, but there you go.

Upvotes: 6

Related Questions