Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/270.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Laravel空数据库给出SQLSTATE[42S02]错误_Php_Mysql_Laravel 5.2 - Fatal编程技术网

Php Laravel空数据库给出SQLSTATE[42S02]错误

Php Laravel空数据库给出SQLSTATE[42S02]错误,php,mysql,laravel-5.2,Php,Mysql,Laravel 5.2,我正在尝试将我的数据库迁移到一个空数据库, 但是,当我执行php artisan迁移时,会出现以下错误: [Illuminate\Database\QueryException] SQLSTATE[42S02]: Base table or view not found: 1146 Table 'portal-for-fun.permissions' doesn't exist (SQL: select * from `permissions`) [PDOExceptio

我正在尝试将我的数据库迁移到一个空数据库, 但是,当我执行php artisan迁移时,会出现以下错误:

  [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
可以在此处找到所有迁移:

但我认为问题在于:

<?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');
    }
}

在项目中创建
权限
模型。

如果您有
权限
型号,请确保
权限中的名称
不是
权限
我也有类似问题。尝试从
migrations
文件夹中删除迁移并移动部分迁移(使用
权限的迁移
表)。首先,您应该运行迁移,该迁移将使用
php artisan migrate
创建
权限
表。然后将创建
permission\u role
permission\u user
表的迁移移回
migrations
文件夹,并再次运行
php artisan migrate


这对我很有帮助,希望它也能对你有所帮助。

删除它并不能解决问题。你迁移后回滚吗?如果我的答案有帮助,请选择我的答案作为最佳答案,并投票表决。