我有很多遷移要遷移,但我的數據庫現在是空的。當我運行時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
}
- 1 回答
- 0 關注
- 207 瀏覽
添加回答
舉報
0/150
提交
取消