我通过迁移重命名破坏了我的 Laravel 框架
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25115006/
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
I broke my Laravel framework with migration renaming
提问by moasking
I had a good working Laravel structure with database migrations and seeding. But I wanted my migration file,classes,db table be renamed to CreateOrganizationsTableinstead of CreateOrganisationsTable
我有一个很好的 Laravel 结构与数据库迁移和播种。但我希望我的迁移文件、类、db 表重命名为CreateOrganizationsTable而不是CreateOrganisationsTable
So I changed the migration filename, all classes and routes.
所以我更改了迁移文件名、所有类和路由。
But when I execute php artisan migrate:resetin my Homestead box, I get the following error:
但是当我php artisan migrate:reset在我的 Homestead 框中执行时,我收到以下错误:
PHP Fatal error: Class 'CreateOrganisationsTable' not found in /home/vagrant/Code/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php on line 299
Artisan created some link I'm unable to fix at the moment.
Artisan 创建了一些我目前无法修复的链接。
回答by DutGRIFF
As Morale mentioned you must reset or rollback to a point before your new migration or make the changes manually. I knew this but was still getting the problem after changing only the timestamps to have the migrations run in a different order.
正如 Morale 提到的,您必须重置或回滚到新迁移之前的某个点,或者手动进行更改。我知道这一点,但在仅更改时间戳以使迁移以不同顺序运行后仍然遇到问题。
You must run composer dump-autoloadeven if you didn't change the class name.
composer dump-autoload即使您没有更改类名,您也必须运行。
回答by code511788465541441
Don't forget to also rename the class inside the file
不要忘记重命名文件中的类
回答by Morale Knitter
The problem is that when you run the migrate:resetcommand, artisan wants to call the down method on all classes. And since you renamed the class, he can't find it anymore!
问题是当你运行migrate:reset命令时,artisan 想要调用所有类的 down 方法。自从你给班级重命名后,他再也找不到了!
So before renaming your class and/or file, run php artisan migrate:resetwhich will clean your database and remove all tables, and right after that simply run php artisan migrate. You should have a working database again.
因此,在重命名您的类和/或文件之前,运行php artisan migrate:reset这将清理您的数据库并删除所有表,然后立即运行php artisan migrate. 您应该再次拥有一个可以工作的数据库。
If the migrate:resetcommand still doesn't work, you can simply delete the tables manually (don't forget to remove the migration table aswell) and run php artisan migrateagain.
如果migrate:reset命令仍然不起作用,您可以简单地手动删除表(不要忘记删除迁移表)并php artisan migrate再次运行。
Edit:In case you don't actually want to run the migrate:reset, but just rename the migration, you can edit the name of the file (and class) . But after that you have to manually edit the table migrationsin your database. Find the corresponding row, and edit the name of the file to match the new name.
编辑:如果您实际上不想运行migrate:reset,而只是重命名迁移,您可以编辑文件(和类)的名称。但之后您必须手动编辑migrations数据库中的表。找到对应的行,并编辑文件名以匹配新名称。
回答by Kelderth
I have had similar problems with the php artisan:rollback, and I just opened my laravel project and went to the next directory:
我在 php artisan:rollback 上也遇到过类似的问题,我刚刚打开我的 Laravel 项目并转到下一个目录:
vendor\composer\autoload_static.php
供应商\作曲家\autoload_static.php
and modified the name of the php migration that was changed, hope this help's you :)
并修改了已更改的 php 迁移名称,希望对您有所帮助:)
回答by Everton Mendon?a
I've performed a composer dump-autoload and everything works fine now
我已经执行了 Composer dump-autoload,现在一切正常
回答by KirtJ
If you're using composer, then I think you forgot to dump-autoload
如果您使用的是作曲家,那么我想您忘记转储自动加载
composer dump-autoload
回答by Haritsinh Gohil
In laravel renaming migration works fine if you do it the right way.
在 laravel 中,如果您以正确的方式进行重命名迁移,则可以正常工作。
i have also renamed my migration files many times, and it works as expected,
我也多次重命名我的迁移文件,它按预期工作,
but if you want to rename the migrationthen you have to take care of two things:
但是如果你想重命名迁移,那么你必须注意两件事:
first rename the filename
open that migration file and rename the Class name also
首先重命名文件名
打开该迁移文件并重命名类名
Renaming the file :
change your filename from 2019_06_28_131130_create_organisations_tableto 2019_06_28_131130_create_organizations_tableor whatever name you want.
重命名文件:将文件名从 更改2019_06_28_131130_create_organisations_table为2019_06_28_131130_create_organizations_table或您想要的任何名称。
Open that migration file and Rename the class name in that fileas per your new name:
打开该迁移文件并根据您的新名称重命名该文件中的类名:
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
//change it from
//class CreateOrganisationsTable extends Migration {
//to
class CreateOrganizationsTable extends Migration {
i think you have renamed the migration file but you have forgotten to rename the Class name so do that and try to run php artisan migrate:refreshit will work as you want.
我认为您已经重命名了迁移文件,但是您忘记了重命名类名,所以这样做并尝试运行php artisan migrate:refresh它会按您的意愿工作。

