未找到Laravel Base表或视图
I'm very confused, i try to find what's wrong but i don't find it..
My migration file:
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
class CreateClientProjectTable extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('client_project', function(Blueprint $table)
{
$table->increments('id');
$table->integer('client_id');
$table->integer('project_id');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('client_project');
}
}
First of all, i check table is created, and it is.
Then, the route who calls to the controller is this: (is prefixed by admin)
Route::post('projectsclients/postUpload', ['uses' => 'AdminController@storeProjectsClients', 'as' => 'admin.projectsclients.store']);
The functions looks like here:
$client_project = new Client_Project();
$client_project->client_id = DB::table('clients')->orderby('id','DESC')->take(1)->get();
$client_project->project_id = DB::table('projects')->orderby('id','DESC')->take(1)->get();
$client_project->save();
And the error:
Base table or view not found: 1146 Table 'web.client__projects' doesn't exist
The problem is my table is client_project not client__projects.
Where i have to fix this?
Thanks a lot, any help will be appreciated.
我很困惑,我试图找到错误但我找不到它.. p >
我的迁移文件: strong> p>
首先,我检查表是否已创建,它是。 p>
然后, 这些函数如下所示: p>
错误: p>
找不到基表或视图:1146表'web.client__projects'
不 存在 p>
blockquote>
问题是我的表是 我必须解决这个问题吗? p>
非常感谢,我们将不胜感激。 p>
div>
&lt;?php
use Illuminate \ Database \ Migrations \ Migration; \ nuse Illuminate \ Database \ Schema \ Blueprint;
class CreateClientProjectTable扩展迁移{
/ **
*运行迁移。
*
* @return void
* /
n公共函数up( )
{
Schema :: create('client_project',function(Blueprint $ table)
{
$ table-&gt; increments('id');
$ table-&gt; integer('client_id' );
$ table-&gt;整数('project_id');
$ table-&gt; timestamps();
});
}
/ **
*反转迁移 。
*
* @return void
* /
public function down()
{
Schema :: drop('client_project');
}
}
code> pre>
route code >谁调用 controller code>是这样的:(以 admin code>为前缀) p>
Route :: post('projectsclients / postUpload',['uses'=&gt; 'AdminController @ storeProjectsClients','as'=&gt; 'admin.projectsclients.store']);
code> pre>
$ client_project = new Client_Project();
$ client_project- &gt; client_id = DB :: table('clients') - &gt; orderby('id','DESC') - &gt; take(1) - &gt; get();
$ client_project-&gt; project_id = DB ::表( '项目') - &GT;的OrderBy( '编号', 'DESC') - &GT;取(1) - &GT;得到();
$的client_project-&GT;保存();
代码> pre>
client_project code>而不是 client__projects code>。 p>
You shouldn't be breaking up class name with _ for one. It should be named ClientProject. Generally if there is a problem with the table you would edit the modal and add a
ClientProject.php
public $table = 'client_project';
You are not following Laravel naming conventions. To solve this particular issue yo can explicitly define tabe name. In class Client_Projects definition add this:
protected $table = 'client_project';
But to learn about naming conventions I suggest reading related section in documents here https://laravel.com/docs/5.4/eloquent#eloquent-model-conventions