Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
416 views
in Technique[技术] by (71.8m points)

php - Laravel migrations: Class "not found"

I am deploying a Laravel barebone project to Microsoft Azure, but whenever I try to execute php artisan migrate I get the error:

[2015-06-13 14:34:05] production.ERROR: exception 'SymfonyComponentDebugExceptionFatalErrorException' with message 'Class '' not found' in D:homesitevendorlaravelframeworksrcIlluminateDatabaseMigrationsMigrator.php:328

Stack trace:

 #0 {main}  

What could be the problem? Thank you very much

-- edit --

Migration Class

<?php
use IlluminateDatabaseSchemaBlueprint;
use IlluminateDatabaseMigrationsMigration;

class CreateUsersTable extends Migration {

    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('users', function(Blueprint $table)
        {
            $table->bigIncrements('id');
            $table->string('name', 50);
            $table->string('surname', 50);
            $table->bigInteger('telephone');
            $table->string('email', 50)->unique();
            $table->string('username', 50)->unique();
            $table->string('password', 50);
            $table->boolean('active')->default(FALSE);
            $table->string('email_confirmation_code', 6);
            $table->enum('notify', ['y', 'n'])->default('y');
            $table->rememberToken();
            $table->timestamps();
            
            $table->index('username');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::drop('users');
    }
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

For PSR-4 Auto Loader Users (composer.json):

Keep the migrations folder inside classmap array and do not include it inside psr-4 object under autoload head. As migrations' main class Migrator doesn't support namespacing. For example;

"autoload": {
    "classmap": [
        "app/database/migrations"
    ],
    "psr-4": {
        "Acme\controllers": "app/controllers"
    }
}

Then run:

php artisan clear-compiled 
php artisan optimize:clear
composer dump-autoload
php artisan optimize
  • First one clears all compiled autoload files.
  • Second clears Laravel caches (optional)
  • Third builds the autoloader for namespaced classes.
  • Fourth optimizes various parts of your Laravel app and builds the autoloader for non-namespaced classes.

From this time on wards, you will not have to do this again and any new migrations will work correctly.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...