我是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 IlluminateDatabaseSchemaBlueprint;
use IlluminateDatabaseMigrationsMigration;
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]);
}
我已经回滚了迁移,刷新了它们,…但它没有帮助……
有谁能帮我吗?您应该在控制台中运行迁移。它在db中创建likes
表。
php artisan migrate
如果您想了解迁移:http://laravel.com/docs/5.1/migrations
试试这个:
创建具有特定表名的模型,在文本编辑器中打开模型,添加以下行:
protected $table = 'tablename';
所以它看起来像这样:
class Gallery extends Model
{
protected $table = 'tablename';
}
运行迁移:
php artisan migrate