Home > Net >  Laravel migration is not working and missing `migrations` table
Laravel migration is not working and missing `migrations` table

Time:09-27

If I run php artisan migrate it fails with Base table or view not found: 1146 Table '*.migrations' doesn't exist.

enter image description here

And the DB is empty.

enter image description here

If I run php artisan migrate:install I see the migration table but it is empty.

enter image description here

DB shows the migrations table but it is empty.

enter image description here

If I then run php artisan migrate again the db is empty again and I get the same error: Base table or view not found: 1146 Table '*.migrations' doesn't exist.

Maybe someone knows whats going on here.

CodePudding user response:

To fix that I needed to add the following code to app/Providers/AppServiceProvider.php:

<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Schema;  # Added this Line

class AppServiceProvider extends ServiceProvider
{
    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        //
    }

    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        Schema::defaultStringLength(191);  # Added this Line
    }
}

Running php artisan migrate:fresh finally result in:

Dropped all tables successfully.
Migration table created successfully.
Migrating: 2014_10_12_000000_create_users_table
Migrated:  2014_10_12_000000_create_users_table (14.68ms)
Migrating: 2014_10_12_100000_create_password_resets_table
Migrated:  2014_10_12_100000_create_password_resets_table (12.33ms)
Migrating: 2019_08_19_000000_create_failed_jobs_table
Migrated:  2019_08_19_000000_create_failed_jobs_table (18.95ms)

Source: Laravel Migration Error: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes

Thanks a lot to Weber and mathijing!!

CodePudding user response:

Could be a couple of things:

  • Try php artisan migrate:reset
  • There could be something wrong in your migration files: check here
  • Related