我正在开发一个项目,我试图在 SQL Server 数据库上设置一些具有架构的表,因此我手动将表名称更改为迁移文件上的 schema_name.table_name 并且它起作用了,所以这里是例子:
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();
:
Illuminate\Database\QueryException 并显示消息“SQLSTATE[42S02]:[Microsoft][ODBC Driver 13 for SQL Server][SQL Server]无效的对象名称“centro_votacions”。 (SQL:从 [centro_votacions] 选择 *)'
当然,我知道没有表“centro_votacions”,有一个名为“electoral.centro_votacions”的表,所以问题是我如何让 laravel 更改查询,以便我可以找到“electoral.centro_votacions”表和其他表我的 SQL Server DB 上的架构?
Inside CentroVotacion
模型定义表名
class CentroVotacion extends Model
{
protected $table = 'electoral.centro_votacions';
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)