为什么我必须运行"composer dump-autoload"?命令使迁移工作在laravel中? [英] Why do I have to run "composer dump-autoload" command to make migrations work in laravel?

查看:342
本文介绍了为什么我必须运行"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:

  [Symfony\Component\Debug\Exception\FatalErrorException]  
  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"
    ],
}

您需要将迁移文件夹的路径添加到classmap数组.然后运行以下三个命令...

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中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆