Laravel 4 迁移 - 找不到类

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14069586/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 07:27:27  来源:igfitidea点击:

Laravel 4 migrations - class not found

migrationlaravel

提问by Euan T

This question is now solved - I used the below:

这个问题现在解决了 - 我使用了以下内容:

And, problem solved thanks to IRC. I was told to run

并且,由于 IRC,问题解决了。我被告知要跑

php composer.phar dump-autoload

This fixes the problem for me. It's likely related to my strange Composer setup.

这为我解决了问题。这可能与我奇怪的 Composer 设置有关。



I've just started playing with Laravel 4 for a possible future project, having come from Laravel 3. I have started off by creating a new migration, create_blogs_table using artisan:

我刚开始在 Laravel 4 中使用 Laravel 4 用于未来可能的项目,来自 Laravel 3。我已经开始使用 artisan 创建一个新的迁移,create_blogs_table:

php artisan migrate:make create_blogs_table --table=blogs --create

This generated the basic migration file structure which I then filled out a little more:

这生成了基本的迁移文件结构,然后我再填写了一点:

<?php

use Illuminate\Database\Migrations\Migration;

class CreateBlogsTable extends Migration
{

    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('blogs', function($table)
        {
            $table->increments('id');
            $table->string('title');
            $table->text('description')->nullable();
            $table->integer('user_id')->unsigned();
            $table->timestamps();
        });
    }

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

I now try to run this migration using artisan once again:

我现在尝试再次使用 artisan 运行此迁移:

php artisan migrate --env=local

*note I have a local database connection set up for domains with the .dev extension

*注意我为带有 .dev 扩展名的域设置了本地数据库连接

Previously this would work just fine (in Laravel 3) but with Illuminate I then receive this error:

以前这可以正常工作(在 Laravel 3 中)但使用 Illuminate 我然后收到此错误:

PHP Fatal error:  Class 'CreateBlogsTable' not found in /var/www/gamingsite/vendor/illuminate/database/src/Illuminate/Database/Migrations/Migrator.php on line 301
PHP Stack trace:
PHP   1. {main}() /var/www/gamingsite/artisan:0
PHP   2. Symfony\Component\Console\Application->run() /var/www/gamingsite/artisan:57
PHP   3. Symfony\Component\Console\Application->doRun() /var/www/gamingsite/vendor/symfony/console/Symfony/Component/Console/Application.php:106
PHP   4. Illuminate\Console\Command->run() /var/www/gamingsite/vendor/symfony/console/Symfony/Component/Console/Application.php:193
PHP   5. Symfony\Component\Console\Command\Command->run() /var/www/gamingsite/vendor/illuminate/console/src/Illuminate/Console/Command.php:95
PHP   6. Illuminate\Console\Command->execute() /var/www/gamingsite/vendor/symfony/console/Symfony/Component/Console/Command/Command.php:240
PHP   7. Illuminate\Database\Console\Migrations\MigrateCommand->fire() /var/www/gamingsite/vendor/illuminate/console/src/Illuminate/Console/Command.php:107
PHP   8. Illuminate\Database\Migrations\Migrator->run() /var/www/gamingsite/vendor/illuminate/database/src/Illuminate/Database/Console/Migrations/MigrateCommand.php:69
PHP   9. Illuminate\Database\Migrations\Migrator->runMigrationList() /var/www/gamingsite/vendor/illuminate/database/src/Illuminate/Database/Migrations/Migrator.php:75
PHP  10. Illuminate\Database\Migrations\Migrator->runUp() /var/www/gamingsite/vendor/illuminate/database/src/Illuminate/Database/Migrations/Migrator.php:106
PHP  11. Illuminate\Database\Migrations\Migrator->resolve() /var/www/gamingsite/vendor/illuminate/database/src/Illuminate/Database/Migrations/Migrator.php:125
PHP Fatal error:  Uncaught exception 'UnexpectedValueException' with message 'The stream or file "/var/www/gamingsite/app/start/../storage/logs/log-2012-12-28.txt" could not be opened: failed to open stream: Permission denied' in /var/www/gamingsite/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php:71
Stack trace:
#0 /var/www/gamingsite/vendor/monolog/monolog/src/Monolog/Handler/RotatingFileHandler.php(77): Monolog\Handler\StreamHandler->write(Array)
#1 /var/www/gamingsite/vendor/monolog/monolog/src/Monolog/Handler/AbstractProcessingHandler.php(37): Monolog\Handler\RotatingFileHandler->write(Array)
#2 /var/www/gamingsite/vendor/monolog/monolog/src/Monolog/Logger.php(214): Monolog\Handler\AbstractProcessingHandler->handle(Array)
#3 /var/www/gamingsite/vendor/monolog/monolog/src/Monolog/Logger.php(278): Monolog\Logger->addRecord(400, Object(Symfony\Component\HttpKernel\Exception\FatalErrorException), Array)
#4 [internal function]: Monolog\Logger->addError(Object(Symfony\Component\HttpKernel\Exception\FatalErrorExcepti in /var/www/gamingsite/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php on line 71
PHP Stack trace:
PHP   1. {main}() /var/www/gamingsite/artisan:0
PHP   2. Symfony\Component\Console\Application->run() /var/www/gamingsite/artisan:57
PHP   3. Symfony\Component\Console\Application->doRun() /var/www/gamingsite/vendor/symfony/console/Symfony/Component/Console/Application.php:106
PHP   4. Illuminate\Console\Command->run() /var/www/gamingsite/vendor/symfony/console/Symfony/Component/Console/Application.php:193
PHP   5. Symfony\Component\Console\Command\Command->run() /var/www/gamingsite/vendor/illuminate/console/src/Illuminate/Console/Command.php:95
PHP   6. Illuminate\Console\Command->execute() /var/www/gamingsite/vendor/symfony/console/Symfony/Component/Console/Command/Command.php:240
PHP   7. Illuminate\Database\Console\Migrations\MigrateCommand->fire() /var/www/gamingsite/vendor/illuminate/console/src/Illuminate/Console/Command.php:107
PHP   8. Illuminate\Database\Migrations\Migrator->run() /var/www/gamingsite/vendor/illuminate/database/src/Illuminate/Database/Console/Migrations/MigrateCommand.php:69
PHP   9. Illuminate\Database\Migrations\Migrator->runMigrationList() /var/www/gamingsite/vendor/illuminate/database/src/Illuminate/Database/Migrations/Migrator.php:75
PHP  10. Illuminate\Database\Migrations\Migrator->runUp() /var/www/gamingsite/vendor/illuminate/database/src/Illuminate/Database/Migrations/Migrator.php:106
PHP  11. Illuminate\Database\Migrations\Migrator->resolve() /var/www/gamingsite/vendor/illuminate/database/src/Illuminate/Database/Migrations/Migrator.php:125

I've checked and the database/migrations/ folder is certainly being autoloaded. I have no idea what the cause for this problem may be. Having asked on IRC and googled I'm still completely clueless so hopefully somebody can help me out here.

我已经检查过,数据库/迁移/文件夹肯定正在自动加载。我不知道这个问题的原因可能是什么。在 IRC 上询问并用谷歌搜索后,我仍然完全一无所知,所以希望有人能在这里帮助我。

Thanks in advance!

提前致谢!

采纳答案by Raftalks

In Laravel 4 (illuminate) migration class do not require you to set unsigned method. You can try this.

在 Laravel 4 (illuminate) 迁移类中不需要你设置 unsigned 方法。你可以试试这个。

  class CreateBlogsTable extends Migration
{

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

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

After having the chat with you, I knew two problems, one is that already mentioned above and the other problem is due to the class not been registered into composer autoload. You will have to run manually : php composer.phar dump-autoload

和你聊天后,我知道了两个问题,一个是上面已经提到的,另一个是因为这个类没有注册到composer autoload中。您必须手动运行:php composer.phar dump-autoload

回答by Thomas Clarkson

I had this error on xubuntu and fixed it with sudo composer dump-autoload

我在 xubuntu 上遇到了这个错误,并用 sudo composer dump-autoload 修复了它

回答by Yarco

Artisan do the same work:

工匠做同样的工作:

php artisan dump-autoload

Just a reminder for those who are not familiar with composer.

只是给不熟悉的人提个醒composer

回答by user3474709

Update your composer (composer self-update), then run your composer functions.

更新您的 Composer ( composer self-update),然后运行您的 Composer 函数。