Heim  >  Artikel  >  Backend-Entwicklung  >  Lösung für das Problem, dass die Tabelle leer ist, wenn der Tabellenmigrationsbefehl in Laravel5.5 ausgeführt wird

Lösung für das Problem, dass die Tabelle leer ist, wenn der Tabellenmigrationsbefehl in Laravel5.5 ausgeführt wird

不言
不言Original
2018-07-06 10:44:502088Durchsuche

Dieser Artikel stellt hauptsächlich die Lösung für das Problem vor, dass die Tabelle beim Ausführen des Tabellenmigrationsbefehls in Laravel5.5 leer ist. Jetzt kann ich es mit Ihnen teilen.

Heute ist bei der Verwendung eines Drittanbieterpakets laravel-admin ein Fehler wie dieser aufgetreten: SQLSTATE[42000]: Syntax error or access violation: 1103 Incorrect table name '' Nach langem Ringen stellte sich heraus, dass der Cache der Konfigurationsdatei wurde nicht geklärt.

1. Problem

vagrant@homestead:~/Code/laravel-shop$ php artisan admin:install

Fehlermeldung:

In Connection.php line 664:

  SQLSTATE[42000]: Syntax error or access violation: 1103 Incorrect table name '' (SQL: create table `` (`id` int uns
  igned not null auto_increment primary key, `username` varchar(190) not null, `password` varchar(60) not null, `name
  ` varchar(255) not null, `avatar` varchar(255) null, `remember_token` varchar(100) null, `created_at` timestamp nul
  l, `updated_at` timestamp null) default character set utf8mb4 collate utf8mb4_unicode_ci)


In Connection.php line 452:

  SQLSTATE[42000]: Syntax error or access violation: 1103 Incorrect table name ''

2. Lösung

database/migrations/2016_01_04_173148_create_admin_table.php

<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;

class CreateAdminTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        $connection = config(&#39;admin.database.connection&#39;) ?: config(&#39;database.default&#39;);

       // dd(app(&#39;config&#39;));
        Schema::connection($connection)->create(config(&#39;admin.database.users_table&#39;), function (Blueprint $table) {
            $table->increments(&#39;id&#39;);
            $table->string(&#39;username&#39;, 190)->unique();
            $table->string(&#39;password&#39;, 60);
            $table->string(&#39;name&#39;);
            $table->string(&#39;avatar&#39;)->nullable();
            $table->string(&#39;remember_token&#39;, 100)->nullable();
            $table->timestamps();
        });

        Schema::connection($connection)->create(config(&#39;admin.database.roles_table&#39;), function (Blueprint $table) {
            $table->increments(&#39;id&#39;);
            $table->string(&#39;name&#39;, 50)->unique();
            $table->string(&#39;slug&#39;, 50);
            $table->timestamps();
        });

        Schema::connection($connection)->create(config(&#39;admin.database.permissions_table&#39;), function (Blueprint $table) {
            $table->increments(&#39;id&#39;);
            $table->string(&#39;name&#39;, 50)->unique();
            $table->string(&#39;slug&#39;, 50);
            $table->string(&#39;http_method&#39;)->nullable();
            $table->text(&#39;http_path&#39;)->nullable();
            $table->timestamps();
        });

        Schema::connection($connection)->create(config(&#39;admin.database.menu_table&#39;), function (Blueprint $table) {
            $table->increments(&#39;id&#39;);
            $table->integer(&#39;parent_id&#39;)->default(0);
            $table->integer(&#39;order&#39;)->default(0);
            $table->string(&#39;title&#39;, 50);
            $table->string(&#39;icon&#39;, 50);
            $table->string(&#39;uri&#39;, 50)->nullable();

            $table->timestamps();
        });

        Schema::connection($connection)->create(config(&#39;admin.database.role_users_table&#39;), function (Blueprint $table) {
            $table->integer(&#39;role_id&#39;);
            $table->integer(&#39;user_id&#39;);
            $table->index([&#39;role_id&#39;, &#39;user_id&#39;]);
            $table->timestamps();
        });

        Schema::connection($connection)->create(config(&#39;admin.database.role_permissions_table&#39;), function (Blueprint $table) {
            $table->integer(&#39;role_id&#39;);
            $table->integer(&#39;permission_id&#39;);
            $table->index([&#39;role_id&#39;, &#39;permission_id&#39;]);
            $table->timestamps();
        });

        Schema::connection($connection)->create(config(&#39;admin.database.user_permissions_table&#39;), function (Blueprint $table) {
            $table->integer(&#39;user_id&#39;);
            $table->integer(&#39;permission_id&#39;);
            $table->index([&#39;user_id&#39;, &#39;permission_id&#39;]);
            $table->timestamps();
        });

        Schema::connection($connection)->create(config(&#39;admin.database.role_menu_table&#39;), function (Blueprint $table) {
            $table->integer(&#39;role_id&#39;);
            $table->integer(&#39;menu_id&#39;);
            $table->index([&#39;role_id&#39;, &#39;menu_id&#39;]);
            $table->timestamps();
        });

        Schema::connection($connection)->create(config(&#39;admin.database.operation_log_table&#39;), function (Blueprint $table) {
            $table->increments(&#39;id&#39;);
            $table->integer(&#39;user_id&#39;);
            $table->string(&#39;path&#39;);
            $table->string(&#39;method&#39;, 10);
            $table->string(&#39;ip&#39;, 15);
            $table->text(&#39;input&#39;);
            $table->index(&#39;user_id&#39;);
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        $connection = config(&#39;admin.database.connection&#39;) ?: config(&#39;database.default&#39;);

        Schema::connection($connection)->dropIfExists(config(&#39;admin.database.users_table&#39;));
        Schema::connection($connection)->dropIfExists(config(&#39;admin.database.roles_table&#39;));
        Schema::connection($connection)->dropIfExists(config(&#39;admin.database.permissions_table&#39;));
        Schema::connection($connection)->dropIfExists(config(&#39;admin.database.menu_table&#39;));
        Schema::connection($connection)->dropIfExists(config(&#39;admin.database.user_permissions_table&#39;));
        Schema::connection($connection)->dropIfExists(config(&#39;admin.database.role_users_table&#39;));
        Schema::connection($connection)->dropIfExists(config(&#39;admin.database.role_permissions_table&#39;));
        Schema::connection($connection)->dropIfExists(config(&#39;admin.database.role_menu_table&#39;));
        Schema::connection($connection)->dropIfExists(config(&#39;admin.database.operation_log_table&#39;));
    }
}

Konfigurationsdatei-Cache löschen

vagrant@homestead:~/Code/laravel-shop$ php artisan config:cache

Führen Sie den Veröffentlichungsbefehl erneut aus und es wird gut sein:

vagrant@homestead:~/Code/laravel-shop$ php artisan admin:install
Migrating: 2016_01_04_173148_create_admin_table
Migrated:  2016_01_04_173148_create_admin_table
Admin directory was created: /app/Admin
HomeController file was created: /app/Admin/Controllers/HomeController.php
ExampleController file was created: /app/Admin/Controllers/ExampleController.php
Bootstrap file was created: /app/Admin/bootstrap.php
Routes file was created: /app/Admin/routes.php
vagrant@homestead:~/Code/laravel-shop$

Das Obige ist der gesamte Inhalt dieses Artikels, der für das Studium aller hilfreich sein wird Achten Sie auf die chinesische PHP-Website!

Verwandte Empfehlungen:

Laravel+Redis implementiert einfach die Verarbeitung von Warteschlangen mit hoher Parallelität, die Stresstests bestehen

Für Nginx Konfigurationsdatei Lösung für den Konfigurationsfehler von fastcgi_param in

Das obige ist der detaillierte Inhalt vonLösung für das Problem, dass die Tabelle leer ist, wenn der Tabellenmigrationsbefehl in Laravel5.5 ausgeführt wird. Für weitere Informationen folgen Sie bitte anderen verwandten Artikeln auf der PHP chinesischen Website!

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn