代码之家  ›  专栏  ›  技术社区  ›  Nelson Candia

Laravel sql server更改架构的表名

  •  1
  • Nelson Candia  · 技术社区  · 7 年前

    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();

    照亮\数据库\查询异常,并显示消息“SQLSTATE[42S02]:[Microsoft][ODBC Driver 13 for SQL Server][SQL Server]无效的对象名“centro\u votacions”。(SQL:从[centro\u votacions]中选择*

    当然我明白了,没有“centro\u votacions”表,有一个叫做“electronic.centro\u votacions”的表,所以问题是,我如何让laravel更改查询,以便在我的SQL Server DB上找到“electronic.centro\u votacions”表和其他模式?。

    1 回复  |  直到 7 年前
        1
  •  5
  •   Anar Bayramov    7 年前

    CentroVotacion 模型定义表名

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