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

标签 php mysql laravel-5

我正在尝试将我的数据库迁移到一个空数据库, 但是当我执行 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

最佳答案

在您的项目中创建权限模型。
如果您有 permission 模型,请确保 permission 中的名称不是 Permission

关于php - Laravel 空数据库给出 SQLSTATE[42S02] 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35534195/

相关文章:

php - 如何从中获取 Cookie curl?

php - 为回显字符串提供 CSS 类

php - 锁表sql+php PDO

php - joinWith 返回空外键值

mysql - sql中使用select子句获取记录的问题

Laravel 数据上传进度条

php - mySQL:具有外键关系的 2 个表的 UPDATE 语句

php - 处理丹麦语特殊字符

php - 将总行数除以所有行的总和 - Laravel

php - 将静态路由添加到应该是动态的路由中?