Laravel5.5でテーブル移行コマンド実行時にテーブルが空になる問題の解決方法

不言
リリース: 2023-04-02 16:28:01
オリジナル
2096 人が閲覧しました

この記事では主にLaravel5.5でテーブル移行コマンドを実行するとテーブルが空になる問題の解決方法を紹介します。ある参考値があるので共有します。困っている友達は参考にしてください

今日、サードパーティのパッケージ laravel-admin を使用すると、次のようなエラーが発生しました: SQLSTATE[42000]: 構文エラーまたはアクセス違反: 1103 テーブル名が正しくありません ''。長い間、ようやく解決策を見つけましたが、設定ファイルのキャッシュがクリアされていないことがわかりました。

1. 問題

vagrant@homestead:~/Code/laravel-shop$ php artisan admin:install
ログイン後にコピー

エラー メッセージ:

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. 解決策

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;));
    }
}
ログイン後にコピー

設定ファイルのキャッシュをクリアします

vagrant@homestead:~/Code/laravel-shop$ php artisan config:cache
ログイン後にコピー

publish コマンドを再度実行すると問題ありません:

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$
ログイン後にコピー

上記がこの記事の全内容です。その他の関連コンテンツについては、PHP 中国語 Web サイトをご覧ください。

関連する推奨事項:

laravel Redis は、ストレス テストに合格したキューの高同時実行処理を実装するだけです

nginx の場合設定ファイル fastcgi_param 設定エラーの解決策

以上がLaravel5.5でテーブル移行コマンド実行時にテーブルが空になる問題の解決方法の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

関連ラベル:
ソース:php.cn
このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
最新の問題
人気のチュートリアル
詳細>
最新のダウンロード
詳細>
ウェブエフェクト
公式サイト
サイト素材
フロントエンドテンプレート
私たちについて 免責事項 Sitemap
PHP中国語ウェブサイト:福祉オンライン PHP トレーニング,PHP 学習者の迅速な成長を支援します!