完全重置 Laravel 5 迁移的东西?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29338806/
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
Completely Reseting Laravel 5 Migration Stuff?
提问by Ben Stock
To make a long story short, I have completely messed up my Laravel migrations on my local machine. They are 100% unusable.
长话短说,我在本地机器上完全搞砸了我的 Laravel 迁移。它们 100% 无法使用。
I'm working with Laravel 5 for the first time, so I'm just messing with stuff and testing the waters, so to speak. Between manually tinkering with the database, rewriting my migrations, accidentally deleting a table or two (then the 'migrations' table itself [doh!]), I'm in this mixed-up state, and I just want to start all of the migration stuff over from scratch. However, I can't seem to figure out how to do that.
我是第一次使用 Laravel 5,所以我只是在捣鼓东西并试水,可以这么说。在手动修改数据库、重写我的迁移、不小心删除一两个表(然后是“迁移”表本身 [doh!])之间,我处于这种混合状态,我只想开始所有的从头开始迁移东西。但是,我似乎无法弄清楚如何做到这一点。
I'm currently stuck in a state where I can't do anything.
我目前陷入了无能为力的状态。
For example, if any remnants of old tables are still in the database when I perform php artisan migrate:refresh
, I get a Base table or view already exists
error message. However, if I delete all the tables, I get this error:
例如,如果我执行时旧表的任何残余仍在数据库中php artisan migrate:refresh
,我会收到一条Base table or view already exists
错误消息。但是,如果我删除所有表,则会收到此错误:
Next exception 'Illuminate\Database\QueryException' with message
'SQLSTATE[42S02]: Base table or view not found: 1146 Table
'bsd_status.projects' doesn't exist (SQL: select * from `projects`)' in
path/to/src/Illuminate/Database/Connection.php:620
I've run the following commands:
我已经运行了以下命令:
$ php artisan clear-compiled
$ php artisan cache:clear
$ php composer dump-autoload
$ php artisan migrate:install
I'm not even sure I'm doing this stuff in the right order. Anyway, other than completely reinstalling Laravel, how does one get all his/her migrations back to "out-of-the-box?" Any help would be greatly appreciated. Thanks!
我什至不确定我是否以正确的顺序做这些事情。无论如何,除了完全重新安装 Laravel,如何让他/她的所有迁移恢复到“开箱即用”状态?任何帮助将不胜感激。谢谢!
回答by Goddard
What I liked to do is manually delete all the tables with what ever tool you use on your device. For me I just use phpmyadmin. After that I do.
我喜欢做的是使用您在设备上使用的任何工具手动删除所有表。对我来说,我只使用 phpmyadmin。在那之后我做。
php artisan migrate:install
php artisan migrate:refresh
Don't know if this is the official way, but it works every time.
不知道这是否是官方方式,但每次都有效。
If you don't want to use phpmyadmin you can just login to mysql via command line
如果您不想使用 phpmyadmin,则可以通过命令行登录 mysql
mysql -u root -p
DROP DATABASE laraveldb;
CREATE DATABASE laraveldb;
回答by Ben Stock
Although @Goddard's answer and @nozzleman's comment were both really helpful (I've used both suggestions several other times, so thank you), the solution had nothing to do with migrations. Well, … other than the fact that I screwed them up to begin with.
尽管@Goddard 的回答和@nozzleman 的评论都非常有帮助(我已经多次使用过这两个建议,所以谢谢您),但该解决方案与迁移无关。嗯,……除了我一开始就把它们搞砸了。
Anyway, nothing I did fixed the issue, so I put on my "think really f'ing hard" hat. After cursing for several minutes, I realized something. It appeared that — even when simply running artisan
from the command line — any routes or providers I had set up were attempting to be "resolved" (or whatever the proper terminology is). Thus, I must have had a call somewhere attempting to get data from the missing table when the app started the bootstrap/init/start/run phase.
无论如何,我没有解决这个问题,所以我戴上了“认真思考”的帽子。诅咒了几分钟后,我意识到了一些事情。看起来——即使只是artisan
从命令行运行——我设置的任何路由或提供者都试图“解析”(或任何正确的术语)。因此,当应用程序启动 bootstrap/init/start/run 阶段时,我一定在某处打电话试图从丢失的表中获取数据。
I decided to make sure I didn't have any weird things going on in my actual code, so I checked in my routes file (app/Http/routes.php) and all my Service Provider files (app/Providers/*) to see if I was trying to retrieve model data in any of them. Lo and behold, I opened app/Providers/AppServiceProvider.php and found this:
我决定确保我的实际代码中没有任何奇怪的事情,所以我检查了我的路由文件(app/Http/routes.php)和我所有的服务提供者文件(app/Providers/*)看看我是否试图检索其中任何一个中的模型数据。瞧,我打开 app/Providers/AppServiceProvider.php 并找到了这个:
AppServiceProvider.php
应用服务提供者.php
public function boot()
{
$layout = 'default';
if ( Request::has('layout') ) {
$layout = Request::input('layout');
}
view()->share('sharedAppData', [
'layout' => $layout,
'projects' => App\Project::all() // <- WTF, mate?
]);
}
If you recall, the table being complained about in the error messages was named "projects." Thus, I was attempting to get all projects at boot, so no matter what I did (at the command line or otherwise), nothing was going to work because my Eloquent
-extended model (App\Project
) was looking for a table that simply didn't exist anymore.
如果您还记得,错误消息中所抱怨的表被命名为“项目”。因此,我试图在启动时获取所有项目,所以无论我做什么(在命令行或其他方式),都没有任何效果,因为我的Eloquent
-extended 模型 ( App\Project
) 正在寻找一个根本不存在的表了。
The moral of the story: Laravel is super complex, I suck at it, and no matter how many times I try to follow the teachings of the great Jeffery Way, I'll forever be a Laran00b.
这个故事的寓意:Laravel 非常复杂,我很讨厌它,无论我尝试遵循伟大的 Jeffery Way 的教导多少次,我都将永远是一个 Laran00b。
回答by Rubén Ruíz
try this:
尝试这个:
composer dump-autoload
composer clear-cache