Laravel迁移而未指定列类型

时间:2019-02-12 21:52:10

标签: php laravel

是否可以创建一个更改现有列但未指定列类型的迁移?

例如,如果要向列中添加评论,可以执行以下操作:

$table->string('column_name')->comment('This is the comment')->change();

但是,我想在updated_at时间戳列中添加一条注释,这似乎是不可能的。

$table->timestamp('updated_at')->comment('This is the comment')->change();

由于Doctrine不支持timestamp作为类型而失败。我还能如何定位updated_at列以添加评论?

我希望有这样的东西:

$table->column('updated_at')->comment('This is the comment')->change();

1 个答案:

答案 0 :(得分:2)

根据laravel documentation,只能更改以下列类型:

Only the following column types can be "changed": bigInteger, binary, boolean, date, dateTime, dateTimeTz, decimal, integer, json, longText, mediumText, smallInteger, string, text, time, unsignedBigInteger, unsignedInteger and unsignedSmallInteger.

您可以在迁移过程中使用raw语句:

\DB::statement("ALTER TABLE `users` MODIFY COLUMN `updated_at ` timestamp NULL COMMENT 'This is the comment'")