Laravel - [PDOException] SQLSTATE [42S02]:未找到基表或视图:1146表'ip.priorities'不存在

时间:2015-10-20 22:33:22

标签: php mysql database laravel

您好我试图使用Laravel 5.1迁移名为ideas_roles_users的表但是我得到了错误

  

[PDOException] SQLSTATE [42S02]:找不到基表或视图:1146表'ip.priorities'不存在。

我对Laravel真的很新,希望有人能帮助我。如你所见,我试图制作一个多对多的表,错误来自类CreateIdeasRolesUsersTable。谢谢。

<?

class CreateIdeasRolesUsersTable extends Migration

{
    public function up()
    {
Schema::create('ideas_roles_users', function (Blueprint $table) {
            $table->integer('id_ideas')->unsigned();
            $table->integer('id_roles')->unsigned();
            $table->integer('id_users')->unsigned();

            $table->primary(['id_ideas', 'id_roles', 'id_users']);


            $table->timestamps();

        });

        Schema::table('priorities', function($table) {
          $table->foreign('id_ideas')->references('id')->on('ideas');
          $table->foreign('id_roles')->references('id')->on('roles');
          $table->foreign('id_users')->references('id')->on('users');
       });


    }
    public function down()
    {
        Schema::drop('ideas_roles_users');
    }
}

我的创意课

<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateIdeasTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('ideas', function (Blueprint $table) {
            $table->increments('id');
            $table->string('nombre');
            $table->string('descripcion');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::drop('ideas');
    }
}

我的用户课程

<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateUsersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('users', function (Blueprint $table) {
            $table->increments('id');
            $table->string('user');
            $table->string('nombre');
            $table->string('appellidoP');
            $table->string('appellidoM');
            $table->string('email')->unique();
            $table->string('password', 60);
            $table->string('pais');
            $table->string('estado');
            $table->string('ciudad');
            $table->rememberToken();
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::drop('users');
    }
}

我的角色课程是:

<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateRolesTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('roles', function (Blueprint $table) {
            $table->increments('id');
            $table->string('nombre');
            $table->longText('descripcion');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::drop('roles');
    }
}

2 个答案:

答案 0 :(得分:0)

问题在于您的代码:Schema::table('priorities', function($table)。它应该是Schema::create()而不是Schema::table(),因为您正在尝试创建表格。如果要修改表,则通常使用Schema::table()

答案 1 :(得分:0)

发现错误。问题是我有'Schema::table('priorities', function($table)'而不是'Schema::table('ideas_roles_users', function($table)',因为我的表名是'ideas_roles_users'。我的错。谢谢