Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Laravel-如何更改列类型(smallInteger=>;字符串)_Laravel - Fatal编程技术网

Laravel-如何更改列类型(smallInteger=>;字符串)

Laravel-如何更改列类型(smallInteger=>;字符串),laravel,Laravel,文档中没有提到随着迁移而更改数据类型 我的DB表中有此列 $table->smallInteger('driverslicensetype')->nullable(); 我正在保存四位数字,但当数字以0(零)开始时,例如0230,它将以230 DB的形式保存。这是错误的 现在我想把这个列的数据类型从smallInteger改为varchar 如何通过迁移实现这一点?要使用模式更改功能,需要DBAL: composer require doctrine/dbal 现在您可以使用ch

文档中没有提到随着迁移而更改数据类型

我的DB表中有此列

$table->smallInteger('driverslicensetype')->nullable();
我正在保存四位数字,但当数字以0(零)开始时,例如0230,它将以230 DB的形式保存。这是错误的

现在我想把这个列的数据类型从smallInteger改为varchar


如何通过迁移实现这一点?

要使用模式更改功能,需要DBAL:

composer require doctrine/dbal
现在您可以使用
change()

如果您更喜欢原始方法(或者如果您的SQL更严格,比如当
driverlicensetype
是外键时),请使用
DB::statement

public function up()
{
    DB::statement('ALTER TABLE foo ...');
}
// ...

我得到了这个错误:
[doctor\DBAL\DBALException]请求的未知数据库类型enum,doctor\DBAL\Platforms\MySQL57Platform可能不支持它。
@lewis4u请用相关代码作为一个新问题来问这个问题。
public function up()
{
    DB::statement('ALTER TABLE foo ...');
}
// ...