2017-07-10 15 views
0

我正在處理一個項目,我想在我的SQL Server數據庫上設置一些架構表,因此我手動將表名稱更改爲schema_name.table_name遷移文件和它的工作,所以這裏有一個例子:Laravel SQL服務器更改表格架構的名稱

Schema::create('electoral.centro_votacions', function (Blueprint $table) { 
     $table->bigInteger('id_estado'); 

     $table->bigInteger('id_municipio'); 

     $table->bigInteger('id_parroquia'); 

     $table->bigInteger('id'); 

     $table->string('nombre'); 

     $table->longText('direccion'); 

     $table->foreign(['id_parroquia','id_municipio','id_estado'])->references(['id','id_municipio','id_estado'])->on('electoral.parroquias'); 
     $table->primary('id'); 
}); 

但是當我努力讓自己在PHP php artisan tinker一個雄辯的查詢它不工作,我只是得到一個錯誤的說法,例如製作查詢App\CentroVotacion::all();

用消息'SQLSTA照亮\ Database \ QueryException TE [42S02]:[Microsoft] [用於SQL Server的ODBC驅動程序13] [SQL Server]無效的對象名稱'centro_votacions'。 (SQL:SELECT * FROM [centro_votacions])」

當然,我明白了,沒有表‘centro_votacions’有一個叫‘electoral.centro_votacions’表,這樣的東西,我是如何讓laravel更改查詢,以便我可以在我的SQL Server數據庫上找到「electoral.centro_votacions」表和其他模式?

+0

分享您CentroVotacion模型了。但是,如果你寫'protected $ table ='electoral.centro_votacions';'你可能會好的 –

+0

實際上似乎工作,但是當我做查詢我沒有得到一個JSON我得到的類名下的CentroVotacion模型這個'Illuminate \ Database \ Eloquent \ Builder {#29709}' –

+0

發佈您的查詢 –

回答

1

CentroVotacion模型中定義的表名

class CentroVotacion extends Model 
{ 
    protected $table = 'electoral.centro_votacions';