Why do I have to run quot;composer dump-autoloadquot; command to make migrations work in laravel?(为什么我必须运行“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 中工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:为什么我必须运行“composer dump-autoload"?命令使
基础教程推荐
- 如何在 Symfony 和 Doctrine 中实现多对多和一对多? 2022-01-01
- 如何在 XAMPP 上启用 mysqli? 2021-01-01
- 使用 PDO 转义列名 2021-01-01
- 在 CakePHP 2.0 中使用 Html Helper 时未定义的变量 2021-01-01
- PHP 守护进程/worker 环境 2022-01-01
- HTTP 与 FTP 上传 2021-01-01
- 在 yii2 中迁移时出现异常“找不到驱动程序" 2022-01-01
- 找不到类“AppHttpControllersDB",我也无法使用新模型 2022-01-01
- Doctrine 2 - 在多对多关系中记录更改 2022-01-01
- phpmyadmin 错误“#1062 - 密钥 1 的重复条目‘1’" 2022-01-01