Totally reselling Laravel 5 Migration Stuff?

In short, I completely messed up my Laravel migrations on my local machine. They are 100% unusable.

This is my first time working with Laravel 5, so I just messed around with the material and tested the waters, so to speak. Between manual mastering with the database, rewriting my migrations, accidentally deleting a table or two (then the “migration” table [doh!] Itself), I enter this mixed state, and I just want to start the entire migration from scratch. However, I cannot figure out how to do this.

I am now stuck in a state where I can’t do anything.

For example, if any remnants of the old tables are still in the database when php artisan migrate:refresh running, I get the error Base table or view already exists . However, if I delete all the tables, I get this error:

 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 executed the following commands:

 $ php artisan clear-compiled $ php artisan cache:clear $ php composer dump-autoload $ php artisan migrate:install 

I'm not even sure that I am doing this in the correct order. In any case, except for a complete reinstall of Laravel, how to return all your migrations back to the "out of the box"? Any help would be greatly appreciated. Thanks!

+5
source share
2 answers

I liked to manually delete all the tables using the tool that you use on your device. For me, I just use phpmyadmin. After that I do.

 php artisan migrate:install php artisan migrate:refresh 

I don't know if this is an official way, but it works every time.

If you do not want to use phpmyadmin, you can simply login to mysql via the command line

 mysql -u root -p DROP DATABASE laraveldb; CREATE DATABASE laraveldb; 
+6
source

Although @Goddard's answers and @nozzleman's comment were very helpful (I have used both sentences several times, so thanks), the solution had nothing to do with migrations. Well ... except that I screwed them up to start with.

In any case, I didn’t fix anything, so I put on my hat "think really f'ing hard". Cursing a few minutes, I realized something. It turned out that even if I simply started artisan from the command line, any routes or providers that I configured tried to be "allowed" (or something like the correct terminology). So I had to call somewhere, trying to get data from a missing table when the application started the boot phase / init / start / run.

I decided to make sure that there were no strange things 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 get the model data in any of them. And so, I opened the application / Providers / AppServiceProvider.php and found this:

AppServiceProvider.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, a table called "projects" was written in the error messages. Thus, I tried to load all the projects at startup, so no matter what I did (on the command line or otherwise), nothing happened because my Eloquent advanced model ( App\Project ) was looking for a table that was just bigger does not exist.

The moral of the story: Laravel is very complex, I suck on it, and no matter how many times I try to follow the teachings of the great Way Jeffrey, I will forever be Laran00b.

+3
source

Source: https://habr.com/ru/post/1216435/


All Articles