Connection.php 第 651 行中的 Laravel QueryException:SQLSTATE[42S02]:未找到基表或视图
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33254674/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel QueryException in Connection.php line 651: SQLSTATE[42S02]: Base table or view not found
提问by Jens Ivens
I'm new to Laravel and have an error. When I try to check my page, I get this error:
我是 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")
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")
This is my migration:
这是我的迁移:
<?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');
}
}
And my function:
而我的功能:
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]);
}
I already rolled back my migrations, refreshed them,... But it doesn't help...
我已经回滚了我的迁移,刷新了它们,...但这无济于事...
Can anyone help me out?
谁能帮我吗?
回答by Peter Kota
You should run migration in the console. It creates the likes
table in the db.
您应该在控制台中运行迁移。它likes
在数据库中创建表。
php artisan migrate
If you would like to know about migrations: http://laravel.com/docs/5.1/migrations
如果您想了解迁移:http: //laravel.com/docs/5.1/migrations
回答by Ehi
Try this:
尝试这个:
Create a model with the particular table name, open the model in your text editor add this line:
创建具有特定表名的模型,在文本编辑器中打开模型,添加以下行:
protected $table = 'tablename';
So it looks like this:
所以它看起来像这样:
class Gallery extends Model
{
protected $table = 'tablename';
}
回答by surfer190
Run the migration:
运行迁移:
php artisan migrate