如何用 migrate 修改字段的 defalut 值

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

如下并不行:

$table->tinyInteger('examine')->default(0)->change();
《L05 电商实战》
从零开发一个电商项目,功能包括电商后台、商品 & SKU 管理、购物车、订单管理、支付宝支付、微信支付、订单退款流程、优惠券等
《L04 微信小程序从零到发布》
从小程序个人账户申请开始,带你一步步进行开发一个微信小程序,直到提交微信控制台上线发布。
最佳答案

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

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

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

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

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

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

下策,改变了字段的类型

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

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

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

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