本文介绍了为什么我必须运行“composer dump-autoload"?命令使迁移在 Laravel 中工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序中构建了一些迁移类来创建我需要的表,但我不断收到错误消息.我需要运行这个命令:

I have built some migration classes in my application to create the tables I need, but I keep getting errors. I need to run this command:

composer dump-autoload

只有这样它才能再次按预期工作.是我做错了什么导致了这个错误还是这是迁移的正常行为?

Only then it works again as expected. Am I doing something wrong that generates this error or this is a normal behaviour with migrations?

以下是我在运行迁移过程时遇到的错误:

Below is the error that I get when running the migration process:

  [SymfonyComponentDebugExceptionFatalErrorException]
  Class 'CreateVideoStatusTable' not found

推荐答案

好的,我想我知道你遇到的问题了.

OK so I think i know the issue you're having.

基本上,由于 Composer 看不到您正在创建的迁移文件,您必须运行 dump-autoload 命令,该命令不会下载任何新内容,但会再次查找它需要包含的所有类.它只是重新生成需要包含在项目中的所有类的列表 (autoload_classmap.php),这就是为什么在您运行该命令后您的迁移工作正常.

Basically, because Composer can't see the migration files you are creating, you are having to run the dump-autoload command which won't download anything new, but looks for all of the classes it needs to include again. It just regenerates the list of all classes that need to be included in the project (autoload_classmap.php), and this is why your migration is working after you run that command.

如何修复它(可能)您需要在 composer.json 文件中添加一些额外的信息.

How to fix it (possibly)You need to add some extra information to your composer.json file.

"autoload": {
    "classmap": [
        "PATH TO YOUR MIGRATIONS FOLDER"
    ],
}

您需要将迁移文件夹的路径添加到类映射数组中.然后运行下面三个命令...

You need to add the path to your migrations folder to the classmap array. Then run the following three commands...

php artisan clear-compiled
composer dump-autoload
php artisan optimize

这将清除当前编译的文件,更新它需要的类,然后将它们写回,这样您就不必再做一次了.

This will clear the current compiled files, update the classes it needs and then write them back out so you don't have to do it again.

理想情况下,您执行 composer dump-autoload -o 以加快网页加载速度.它不是默认值的唯一原因是它需要更长的时间来生成(但只是稍微值得注意).

Ideally, you execute composer dump-autoload -o , for a faster load of your webpages. The only reason it is not default, is because it takes a bit longer to generate (but is only slightly noticable).

希望你能设法解决这个问题,因为它确实很烦人:(

Hope you can manage to get this sorted, as its very annoying indeed :(

这篇关于为什么我必须运行“composer dump-autoload"?命令使迁移在 Laravel 中工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 17:03