-1

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's empty.

enter image description here

DB shows the migrations table but it's 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.

Atika
  • 1,025
  • 2
  • 6
  • 17
Dirk Schiller
  • 491
  • 6
  • 18
  • you want to migrate fresh project migration files or ...? – borisoft82 Sep 26 '21 at 08:21
  • Yes, there are already some migration files for the tables `users`, `password_reset` and `failed_jobs`. – Dirk Schiller Sep 26 '21 at 08:27
  • is there anything inside your boot() method in the AppServiceProvider or any model execution inside route file (as closure)? – borisoft82 Sep 26 '21 at 08:34
  • No, `register()` and `boot()` are empty. – Dirk Schiller Sep 26 '21 at 08:39
  • When I delete `database/mysql-schema.dump` and remove the tables from the db via pypMyAdmin and I run `php artisan migrate` then I get `Migration table created successfully. Migrating: 2014_10_12_000000_create_users_table SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes (SQL: alter table 'users' add unique 'users_email_unique'('email'))` – Dirk Schiller Sep 26 '21 at 08:47

2 Answers2

1

Could be a couple of things:

  • Try php artisan migrate:reset
  • There could be something wrong in your migration files: check here
mathijng
  • 153
  • 2
  • 10
  • `php artisan migrate:reset` shows `Nothing to rollback.`. And then `php artisan migrate` brings the same errors `SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'users' already exists`. Also `php artisan optimize:clear` doesn't make a difference. `Compiled views cleared! Application cache cleared! Route cache cleared! Configuration cache cleared! Compiled services and packages files removed! Caches cleared successfully!` – Dirk Schiller Sep 26 '21 at 08:51
  • `php artisan migrate:fresh` also fails with `Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes (SQL: alter table 'users' add unique 'users_email_unique'('email'))` – Dirk Schiller Sep 26 '21 at 08:54
  • 1
    Then I would try to add 'Schema::defaultStringLength(191);' to your AppServiceProvider file. Like here: https://stackoverflow.com/a/42245921/13146915 – mathijng Sep 26 '21 at 08:55
  • 1
    Holy s**. That worked!!! `php artisan migrate:fresh` 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)` – Dirk Schiller Sep 26 '21 at 08:59
1

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!!

Dirk Schiller
  • 491
  • 6
  • 18