3

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

Asim Naseer
  • 143
  • 1
  • 3
  • 11

3 Answers3

0

You should use string , there it is :

$table->string('name');

It`s will work for you .

BENY
  • 41
  • 9
  • 1
    datatype string is defied for varchar but still SQL server create a datatype of nvarchar. Migration DB code is attached along with the question. – Asim Naseer Aug 08 '17 at 08:39
0

Check your database type in config/database.php file.

The default is MySQL, but if you are using MS SQL, it should be 'default' => 'sqlsrv', in database.php

Ahsan
  • 1,289
  • 3
  • 13
  • 37
  • sqlsrv been already set in the config/database as default while running the migration. But still you can see as the attache image shows migration create a datatype of nvarchar instead of varchar – Asim Naseer Aug 08 '17 at 08:38
0

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.

jlcfly
  • 21
  • 1