Completely Reseting Laravel 5 Migration Stuff?

13,240

Solution 1

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.

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

mysql -u root -p
DROP DATABASE laraveldb;
CREATE DATABASE laraveldb;

Solution 2

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.

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.

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:

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, 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.

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.

Share:
13,240
Ben Stock
Author by

Ben Stock

I'm just a dude trying to make a living as a web developer in this crazy mixed-up world. In my free time, I like to mess with C/Objective-C, and hang out with my pets.

Updated on June 27, 2022

Comments

  • Ben Stock
    Ben Stock almost 2 years

    To make a long story short, I have completely messed up my Laravel migrations on my local machine. They are 100% unusable.

    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.

    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:

    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!

  • pr00thmatic
    pr00thmatic almost 9 years
    it works for me!! anyway, it would be awesome to have the backup of the official documentation, so i can rely on this method :)
  • Nico Haase
    Nico Haase about 5 years
    Why? Please add some explanation to your code, especially because other answers look completely different
  • Rubén Ruíz
    Rubén Ruíz about 5 years
    I see that in other responses and work for me, I am not sure what files cleans exactly but it works.