【问题标题】:Laravel - [PDOException] SQLSTATE[42S02]: Base table or view not found: 1146 Table 'ip.priorities' doesn't existLaravel - [PDOException] SQLSTATE [42S02]:未找到基表或视图:1146 表 'ip.priorities' 不存在
【发布时间】:2016-01-19 18:44:10
【问题描述】:

您好,我正在尝试使用 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');
    }
}

【问题讨论】:

    标签: php mysql database laravel


    【解决方案1】:

    问题在于您的代码:Schema::table('priorities', function($table)。它应该是Schema::create() 而不是Schema::table(),因为您正在尝试创建一个表。 Schema::table() 常用来修改表。

    【讨论】:

    • 您好,感谢您抽空回答。我发现了错误,不是“Schema::table”,而是我有 'Schema::table('priorities', function($table)' 而不是 'Schema::table('ideas_roles_users', function( $table)' 因为我的表名是 'ideas_roles_users'。再次感谢。
    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 2018-03-16
      • 2020-06-26
      • 1970-01-01
      • 2016-07-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-22
      • 2018-04-19
      相关资源
      最近更新 更多