如何用 migrate 修改字段的 defalut 值

topics里的examine值原来是nullable,现在修改成default(0)怎么改呢?

如下并不行:

$table->tinyInteger('examine')->default(0)->change();
《L05 电商实战》
从零开发一个电商项目,功能包括电商后台、商品 & SKU 管理、购物车、订单管理、支付宝支付、微信支付、订单退款流程、优惠券等
《G01 Go 实战入门》
从零开始带你一步步开发一个 Go 博客项目,让你在最短的时间内学会使用 Go 进行编码。项目结构很大程度上参考了 Laravel。
最佳答案

{注} 只有下面的字段类型能被 "修改": bigInteger、 binary、 boolean、date、dateTime、dateTimeTz、decimal、integer、json、 longText、mediumText、smallInteger、string、text、time、 unsignedBigInteger、unsignedInteger and unsignedSmallInteger。

文档上有个 Tips,你这种字段类型不能这样修改吧。

6年前 评论
wongvio (楼主) 6年前
讨论数量: 3

{注} 只有下面的字段类型能被 "修改": bigInteger、 binary、 boolean、date、dateTime、dateTimeTz、decimal、integer、json、 longText、mediumText、smallInteger、string、text、time、 unsignedBigInteger、unsignedInteger and unsignedSmallInteger。

文档上有个 Tips,你这种字段类型不能这样修改吧。

6年前 评论
wongvio (楼主) 6年前

下策,改变了字段的类型

$table->integer('examine')->default(0)->change();
6年前 评论

确实官方文档说了tinyint不能被修改。 还有个办法,用原生sql写修改语句:

DB::statement("ALTER TABLE table1 MODIFY COLUMN column1 TINYINT NOT NULL DEFAULT 0 COMMENT '注释'");
5年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!