0

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.

1
  • Try to re-run composer install Commented Dec 24, 2013 at 3:17

2 Answers 2

6

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.

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

1 Comment

Very useful tip, and since I didn't even mention how I was trying to fake out the migration with my own filenames, I'm all the more grateful.
-1

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.

Comments

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.