【发布时间】:2017-04-25 10:27:38
【问题描述】:
如何将 Laravel 5.3 设置为使用 VARCHAR 而不是 NVARCHAR 进行 mssql 上的迁移?有没有办法做到这一点?
这个问题也适用于 SMALLDATETIME 超过 DATETIME。
【问题讨论】:
标签: sql-server laravel-5 laravel-migrations
如何将 Laravel 5.3 设置为使用 VARCHAR 而不是 NVARCHAR 进行 mssql 上的迁移?有没有办法做到这一点?
这个问题也适用于 SMALLDATETIME 超过 DATETIME。
【问题讨论】:
标签: sql-server laravel-5 laravel-migrations
这是可行的,但你可能必须自己创建一个新的数据库驱动程序,这涉及到
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
【讨论】:
我创建了一个包,可让您进行自定义迁移,而无需自行扩展所有内容。
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');
【讨论】: