亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在 laravel 中運行遷移時出現意外錯誤(表不存在)

在 laravel 中運行遷移時出現意外錯誤(表不存在)

PHP
qq_笑_17 2023-10-22 21:57:06
我有很多遷移要遷移,但我的數據庫現在是空的。當我運行時php artisan migrate出現此錯誤:PDOException::("SQLSTATE[42S02]: Base table or view not found: 1146 Table 'shop.permissions' doesn't exist")這是我的權限遷移:Schema::create('permissions', function (Blueprint $table) {        $table->id();        $table->string('name');        $table->string('label')->nullable();        $table->timestamps();    });    Schema::create('permission_user', function (Blueprint $table) {        $table->unsignedBigInteger('permission_id');        $table->foreign('permission_id')->references('id')->on('permissions')->onDelete('cascade');        $table->unsignedBigInteger('user_id');        $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');        $table->primary(['permission_id', 'user_id']);    });    Schema::create('roles', function (Blueprint $table) {        $table->id();        $table->string('name');        $table->string('label')->nullable();        $table->timestamps();    });    Schema::create('permission_role', function (Blueprint $table) {        $table->unsignedBigInteger('permission_id');        $table->foreign('permission_id')->references('id')->on('permissions')->onDelete('cascade');        $table->unsignedBigInteger('role_id');        $table->foreign('role_id')->references('id')->on('roles')->onDelete('cascade');        $table->primary(['permission_id', 'role_id']);    });    Schema::create('role_user', function (Blueprint $table) {        $table->unsignedBigInteger('user_id');        $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');        $table->unsignedBigInteger('role_id');        $table->foreign('role_id')->references('id')->on('roles')->onDelete('cascade');        $table->primary(['user_id', 'role_id']);    });當我在數據庫中創建權限手冊并運行php artisan migrate它時不會出現此錯誤,但經過一些遷移后我收到此錯誤:SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'permissions' already exists我可以做什么來遷移我的表?
查看完整描述

1 回答

?
森欄

TA貢獻1810條經驗 獲得超5個贊

通常,當您讓服務提供商查詢權限(通常是為了設置授權門)時,就會出現這個問題。每次啟動應用程序(包括在控制臺中)時都會啟動服務提供程序。當數據庫為空時,沒有可查詢的表。


如果您出于授權目的執行此查詢,則在控制臺中運行時可能不需要執行此操作,因為沒有傳入的 Web 請求。如果您愿意,可以嘗試將您正在執行的操作設置為有條件的嘗試如果在控制臺中運行則不運行;在服務提供商中:


if (! $this->app->runningInConsole()) {

    // not running in console

}


查看完整回答
反對 回復 2023-10-22
  • 1 回答
  • 0 關注
  • 207 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號