php 迁移时未找到 Laravel 致命错误类
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24413929/
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
Laravel Fatal Error Class Not Found when migrating
提问by Wistar
- I've run
artisan migrate:reset
. - I've deleted some of my migration files because I didn't need these tables anymore.
- I ran
composer dump-autoload
followed byartisan dump-autoload
I ran
artisan migrate
and I keep getting this error:PHP Fatal error: Class 'Foo' not found in /vagrant/LaravelBackend/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php on line 297
- 我已经运行
artisan migrate:reset
。 - 我删除了一些迁移文件,因为我不再需要这些表了。
- 我
composer dump-autoload
跟着跑artisan dump-autoload
我跑了
artisan migrate
,我一直收到这个错误:PHP 致命错误:在第 297 行的 /vagrant/LaravelBackend/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php 中找不到“Foo”类
I tried to:
我试过了:
- Run again
composer dump-autoload
andartisan dump-autoload
(also usedartisan clear-compiled
) - Remove the migration table and run
artisan migrate:install
- Remove the vendor and composer.lock file and run
composer install
Search within my project with PHPStorm for class Foo. Didn't find anything.
I keep getting the same error. It's the first time I run this since I updated to 4.2 if that could be related. Anything else I should be looking for?
- 再次运行
composer dump-autoload
和artisan dump-autoload
(也使用artisan clear-compiled
) - 删除迁移表并运行
artisan migrate:install
- 删除 vendor 和 composer.lock 文件并运行
composer install
使用 PHPStorm 在我的项目中搜索 Foo 类。没有找到任何东西。
我不断收到同样的错误。这是我第一次运行它,因为我更新到 4.2,如果这可能相关的话。还有什么我应该寻找的吗?
回答by Juljan
I had this problem too. Must remember: class name must be in accordance with filename. Simple file renaming helped me:)
我也有这个问题。必须记住:类名必须与文件名一致。简单的文件重命名帮助了我:)
For example: in file "2014_12_08_100923_create_items_tables.php" must be class with name "CreateItemsTables" with using CamelCase words.
例如:在文件“2014_12_08_100923_create_items_tables.php”中,必须是名称为“CreateItemsTables”的类,使用驼峰式单词。
回答by Wistar
I solved my problem by
我解决了我的问题
- Removing all migration
- Running
composer dump-autoload
- Adding them back one by one and running
php artisan migrate
- Deleting those that caused Laravel to throw an error
- Create new migrations to replace the deleted ones
- 删除所有迁移
- 跑步
composer dump-autoload
- 将它们一一添加并运行
php artisan migrate
- 删除导致 Laravel 抛出错误的那些
- 创建新的迁移以替换已删除的迁移
I'm not sure why that worked but my guess is that I might have modified the class name of these problematic migrations in the past.
我不确定为什么会这样,但我的猜测是我过去可能修改了这些有问题的迁移的类名。
I also found that renaming the migration with its initial name (The one throwed with the fatal error) also works for some of them.
我还发现使用初始名称重命名迁移(抛出致命错误的那个)也适用于其中一些。
回答by Stan
I ran into this aswell and the solution was different to all of the above. The reason it was failing was because the filename was still mentioned in the migrations table of the DB. Because there were no unique columns I couldn't remove it with PHPMyAdmin and had to tak the CLI route.
我也遇到了这个问题,解决方案与上述所有解决方案都不同。失败的原因是文件名仍然在数据库的迁移表中提到。因为没有唯一的列,我无法使用 PHPMyAdmin 将其删除,并且不得不采用 CLI 路由。
Login to your server as root. Type the following:
以 root 身份登录到您的服务器。键入以下内容:
mysql -p database_name
(it now prompts for your password. From here on out everything is preceded with mysql >which just means that you're in the Mysql environment.
(它现在提示您输入密码。从这里开始,所有内容都以mysql >开头,这仅表示您处于 Mysql 环境中。
select * from migrations;
Look for the migration file you removed and copy the name.
查找您删除的迁移文件并复制名称。
delete from migrations where migration = '2015_07_21_000119_create_some_table';
It should mention something about 1 row affected. Now verify that it's gone by typing the first command again:
它应该提到有关 1 行受影响的内容。现在通过再次输入第一个命令来验证它是否消失了:
select * from migrations;
If it's gone exit the Mysql environment by typing
如果它消失了,请输入以下命令退出 Mysql 环境
exit;
Now try 'php artisan migrate:rollback' again and it should work like a charm :-)
现在再次尝试“ php artisan migrate:rollback”,它应该像魅力一样工作:-)
回答by John Mccandles
There is an easier way.
有一个更简单的方法。
- Recreate those delete migrations manually.
artisan make:migration
- run
artisan migrate:reset
to rollback - Delete those dummy migations files just created.
- run
artisan migrate:refresh
- 手动重新创建这些删除迁移。
artisan make:migration
- 运行
artisan migrate:reset
回滚 - 删除刚刚创建的那些虚拟迁移文件。
- 跑
artisan migrate:refresh
回答by YahyaE
I know this is a bit past but there is a better way actually. Run the following in terminal and feel free yourself to remove any of them:
我知道这有点过去了,但实际上有更好的方法。在终端中运行以下命令并随意删除它们中的任何一个:
~$ php artisan clear-compiled;php artisan cache:clear;php artisan config:clear;php artisan debugbar:clear;php artisan view:clear;php artisan optimize
To do it a regular task create an executable file named artisan-clear:
为此,常规任务创建一个名为 artisan-clear 的可执行文件:
#!/bin/bash
php artisan clear-compiled
php artisan cache:clear
php artisan config:clear
php artisan debugbar:clear
php artisan view:clear
php artisan optimize
回答by xatzistnr
The actual solution is to use the correct naming for your translations. You still may need to do a
实际的解决方案是为您的翻译使用正确的命名。你可能还需要做一个
composer dump-autoload
composer dump-autoload
The migration files must be as follows
YYYY_MM_DD_000000_create_some_table.php
and the class name inside must be
迁移文件必须如下
YYYY_MM_DD_000000_create_some_table.php
,里面的类名必须是
class CreateSomeTable extends Migration{}
class CreateSomeTable extends Migration{}
回答by Bay879
For me, the solution was that my class name inside the migration somehow started with a lowercase letter. When I changed the class name to be all upper case, then ran a composer dump-autoload
, it ended up working for me. This is using Laravel 5.1, for what it's worth.
对我来说,解决方案是我在迁移中的类名以某种方式以小写字母开头。当我将类名更改为全部大写,然后运行 a 时composer dump-autoload
,它最终对我有用。这是使用 Laravel 5.1,它的价值。
回答by Abduhafiz
I did like this: 1. Deleted row non exist migration from migrations table from database 2. And run the command php artisan migrate:refresh
我是这样做的: 1. 从数据库的迁移表中删除不存在的行迁移 2. 并运行命令 php artisan migrate:refresh
This helped to solve my problem.
这有助于解决我的问题。
*all your data will deleted from database tables
*您的所有数据将从数据库表中删除
回答by Qh0stM4N
version 5.1.3 same problem fix it me:
版本 5.1.3 同样的问题修复它我:
- drop database all tables
- php artisan migrate:status
- 删除数据库所有表
- php工匠迁移:状态
output: No migrations found.
ok use it
输出:No migrations found.
好的使用它
- php artisan migrate:install
- php artisan migrate
- php artisan 迁移:安装
- php工匠迁移
output is:
输出是:
Migrated: 2016_11_24_093015_dt_some_table
Migrated: 2016_12_05_141004_dt_some_table
Migrated: 2016_12_07_110518_dt_some_table
Migrated: 2016_12_08_141807_dt_some_table
Migrated: 2016_12_13_090832_dt_some_table
this problem is solved
这个问题解决了
回答by Mihai Cr?i??
If artisan doesn't work at all and keeps throwing you this message no matter the command you give, delete the config.php
file from bootstrap/cache
folder.
如果 artisan 根本不起作用,并且无论您发出什么命令都不断向您抛出此消息,请config.php
从bootstrap/cache
文件夹中删除该文件。
After that run again
之后再次运行
php artisan config:cache