我如何设置Laravel 5.3在NVARCHAR上使用VARCHAR进行mssql上的迁移?有没有办法做到这一点?
这个问题也适用于DATETIME的SMALLDATETIME。
我创建了一个包,允许您进行自定义迁移,而无需自己扩展所有内容的麻烦。
https://github.com/shiftonelabs/laravel-nomad
安装软件包后,只需更改迁移即可使用新的passthru
方法,并为您的字段提供所需的定义。
// pass definition as third parameter
$table->passthru('string', 'username', 'varchar(60)');
$table->passthru('datetime', 'expires_at', 'smalldatetime');
// or use fluent definition method
$table->passthru('string', 'username')->definition('varchar(60)');
$table->passthru('datetime', 'expires_at')->definition('smalldatetime');
// if there is no defintion, it defaults to the first parameter
$table->passthru('smalldatetime', 'expires_at');
它是可行的,但您可能必须自己创建一个新的数据库驱动程序,这涉及到创建
DatabaseManager
Connection
ConnectionFactory
Schema Builder
Schema Grammar
...
好的部分是你可能可以扩展Laravel中的所有人,只改变语法类:
/**
* Create the column definition for a string type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeString(Fluent $column)
{
return 'NVARCHAR ('.$column->length.')';
}
这个包中的一个例子:
https://github.com/jacquestvanzuydam/laravel-firebird/tree/5.3-support/src/Firebird