繁体   English   中英

Connection.php行651中的Laravel QueryException:SQLSTATE [42S02]:找不到基表或视图

[英]Laravel QueryException in Connection.php line 651: SQLSTATE[42S02]: Base table or view not found

我是Laravel新手,出现错误。 当我尝试检查我的页面时,出现此错误:

QueryException in Connection.php line 651: SQLSTATE[42S02]: Base table or view not found: 1146 Table "scotchbox.likes" doesn't exist (SQL: select "users".*, "users"."name", "projects"."title" from "likes" inner join "users" on "user_id" = "users"."id" inner join "projects" on "project_id" = "projects"."id")

这是我的迁移:

<?php

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

class CreateLikesTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('likes', function(Blueprint $table){
            $table->increments('id');
            $table->integer('project_id');
            $table->integer('user_id');
            $table->softDeletes();
            $table->timestamps();
        });
    }

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

而我的功能:

public function activity()
{
    $likes = DB::table('likes')
        ->join('users', 'user_id', '=', 'users.id')
        ->join('projects', 'project_id', '=', 'projects.id')
        ->select('users.*', 'users.name', 'projects.title')
        ->get();

    return view('user.activity', ['likes' => $likes]);
}

我已经回滚了我的迁移,刷新了它们,...但这无济于事...

谁能帮我吗?

您应该在控制台中运行迁移。 它在数据库中创建likes表。

php artisan migrate

如果您想了解迁移: http : //laravel.com/docs/5.1/migrations

尝试这个:

创建具有特定表名的模型,在文本编辑器中打开模型,添加以下行:

protected $table = 'tablename';

所以看起来像这样:

class Gallery extends Model
{
    protected $table = 'tablename';
}

运行迁移:

php artisan migrate

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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