我有很多遷移要遷移,但我的數(shù)據(jù)庫現(xiàn)在是空的。當(dāng)我運(yùn)行時php artisan migrate出現(xiàn)此錯誤:PDOException::("SQLSTATE[42S02]: Base table or view not found: 1146 Table 'shop.permissions' doesn't exist")這是我的權(quán)限遷移: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']); });當(dāng)我在數(shù)據(jù)庫中創(chuàng)建權(quán)限手冊并運(yùn)行php artisan migrate它時不會出現(xiàn)此錯誤,但經(jīng)過一些遷移后我收到此錯誤:SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'permissions' already exists我可以做什么來遷移我的表?
1 回答

森欄
TA貢獻(xiàn)1810條經(jīng)驗(yàn) 獲得超5個贊
通常,當(dāng)您讓服務(wù)提供商查詢權(quán)限(通常是為了設(shè)置授權(quán)門)時,就會出現(xiàn)這個問題。每次啟動應(yīng)用程序(包括在控制臺中)時都會啟動服務(wù)提供程序。當(dāng)數(shù)據(jù)庫為空時,沒有可查詢的表。
如果您出于授權(quán)目的執(zhí)行此查詢,則在控制臺中運(yùn)行時可能不需要執(zhí)行此操作,因?yàn)闆]有傳入的 Web 請求。如果您愿意,可以嘗試將您正在執(zhí)行的操作設(shè)置為有條件的嘗試如果在控制臺中運(yùn)行則不運(yùn)行;在服務(wù)提供商中:
if (! $this->app->runningInConsole()) {
// not running in console
}
- 1 回答
- 0 關(guān)注
- 222 瀏覽
添加回答
舉報
0/150
提交
取消