繁体   English   中英

Laravel迁移而未指定列类型

[英]Laravel migration without specifying the column type

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

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

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

但是,我想在“ updated_at timestamp”列中添加一条注释,这似乎是不可能的。

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

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

我希望有这样的东西:

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

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

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'")

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM