简体   繁体   中英

Laravel - [PDOException] SQLSTATE[42S02]: Base table or view not found: 1146 Table 'ip.priorities' doesn't exist

Hello im trying to migrate a table named ideas_roles_users with Laravel 5.1 but im getting the error

[PDOException] SQLSTATE[42S02]: Base table or view not found: 1146 Table 'ip.priorities' doesn't exist.

I'm really new with Laravel, hope anyone can help me. As you see im trying to make a table many to many and the error becomes from class CreateIdeasRolesUsersTable . Thank you.

<?

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

My class for Ideas

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

my class for users

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

My class for Roles is:

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

问题是你的代码: Schema::table('priorities', function($table)它应该是。 Schema::create()不是Schema::table()因为你试图创建一个表。 Schema::table()如果要修改表,通常使用Schema::table()

Found the error. The problem it was that I had 'Schema::table('priorities', function($table)' and not 'Schema::table('ideas_roles_users', function($table)' because my table name is 'ideas_roles_users'. My bad. Thank you

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM