我正在尝试将数据库迁移到空数据库,
但是当我php artisan migrate
时出现以下错误:
[Illuminate\Database\QueryException]
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'portal-for-fun.permissions' doesn't exist (SQL: select *
from `permissions`)
[PDOException]
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'portal-for-fun.permissions' doesn't exist
可以在此处找到所有迁移:https://github.com/cskiwi/portal-for-fun/tree/master/database
但我认为问题出在这里:
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateRolesTables extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up() {
Schema::create('roles', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('label')->nullable();
$table->integer('role_id')->unsigned()->nullable();
$table->timestamps();
$table->foreign('role_id')->references('id')->on('roles')->onDelete('cascade');
});
Schema::create('permissions', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('label')->nullable();
$table->timestamps();
});
Schema::create('permission_role', function (Blueprint $table) {
$table->integer('permission_id')->unsigned();
$table->integer('role_id')->unsigned();
$table->foreign('permission_id')->references('id')->on('permissions')->onDelete('cascade');
$table->foreign('role_id')->references('id')->on('roles')->onDelete('cascade');
$table->primary(['permission_id', 'role_id']);
});
Schema::create('role_user', function (Blueprint $table) {
$table->integer('role_id')->unsigned();
$table->integer('user_id')->unsigned();
$table->foreign('role_id')->references('id')->on('roles')->onDelete('cascade');
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
$table->primary(['role_id', 'user_id']);
});
Schema::create('permission_user', function (Blueprint $table) {
$table->integer('permission_id')->unsigned();
$table->integer('user_id')->unsigned();
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
$table->foreign('permission_id')->references('id')->on('permissions')->onDelete('cascade');
$table->primary(['permission_id', 'user_id']);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down() {
Schema::dropIfExists('permission_user');
Schema::dropIfExists('role_user');
Schema::dropIfExists('permission_role');
Schema::dropIfExists('permissions');
Schema::dropIfExists('roles');
}
}
数据库本身只包含一个空的migration
表
答案 0 :(得分:0)
在项目中创建permission
模型
如果您拥有permission
模型,请确保permission
中的名称不是Permission
答案 1 :(得分:0)
我有类似的问题。尝试从permissions
文件夹中分离迁移并移动部分迁移(使用migrations
表的那些)。首先,您应该运行迁移,这将使用permissions
创建php artisan migrate
表。然后将创建permission_role
和permission_user
表的迁移移回migrations
文件夹,然后再次运行php artisan migrate
。
这对我有所帮助,希望它也会帮助你。