I'm trying to work with Laravel 10 and have noticed that when trying to define a Microsoft SQL Server schema on my migrations or in the database config file the artisan command either segmentation faults, or the schema prefix is ignored and my tables are created in the dbo schema.
I've tried defining my table names like you would in a SQL Server statement as schema_name.table_name
to try and create my tables in the desired schema_name
like so
public function up(){
Schema::create('schema_name.table_name', function(Blueprint $table){
//...
});
}
I've also tried going into the database.php
config file to my sqlsrv connection and setting the prefix option like so:
'connection' => [
//...
'sqlsrv' => [
//...
'prefix' => 'schema_name.',
],
],
Both of these just cause the php artisan migrate
command to segmentation fault. If I remove the period that's separating the schema_name from the table_name the command will run, but will create the tables in the dbo
schema and just smoosh the two strings together to create a schema_nametable_name
table.
I've also tried adding a prefix
options on my sqlsrv connection in the database.php config file as I noticed the Postgres SQL connection has it as being definable like so:
'connection' => [
//...
'sqlsrv' => [
//...
'schema' => 'schema_name',
],
],
But it doesn't do anything.
I'm starting to think I'd have to dig through the actual core files of the Framework to find where the actual SQL statements are being generated for these migrations and either modify them directly or create a Facade/ServiceContainer or something to extend the functionality or something.
Digging deeper I can't find anything in the code that will allow for the defining of a SQL Server schema on the migration. But as AlwaysLearning suggested setting up a specific SQL Server account that has its default schema set to the desired SQL Server schema will allow your migrations to create tables in the desired schema.