Laravel, SQL varchar

Viewed 1797

I am Using laravel with MS SQL. When string datatype is defined in the migration (code attahced) laravel create a nvarchar datatype in the Database instead of varchar. How to restrict laravel or SQL Server to create varchar datatype when a datatype of string is defined in migration.

Following is the code for migration

public function up()
{
    Schema::create('ie_applicant_type', function (Blueprint $table) {
        $table->increments('applicant_type_id');
        $table->string('applicant_type');
        $table->timestamps();
    });
}

and sqlsrv is default in config/database

'default' => env('DB_CONNECTION', 'sqlsrv')

but still nvarchar data type is created when the migration is run instead of varchar. SQL Pic attached

Datatype created on running the migration

3 Answers

I know this is an older question, but putting an answer in for anyone stumbling upon this.

The nvarchar is hard-coded. The beauty is that this is all just PHP, so you can change that. If you prefer varchar over nvarchar, just change it in laravel/framework/src/Illuminate/Database/Schema/Grammars/SqlServerGrammar.php

Just change the nvarchars in there to varchars.

Unfortunately, there's nothing in the migration stuff to give you control over this on a column-by-column level. You'd have to choose up front to leave it nvarchar for everything or nvarchar for everything.

Related