如何用 migrate 修改字段的 defalut 值

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

如下并不行:

$table->tinyInteger('examine')->default(0)->change();
《L04 微信小程序从零到发布》
从小程序个人账户申请开始,带你一步步进行开发一个微信小程序,直到提交微信控制台上线发布。
《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,你这种字段类型不能这样修改吧。

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

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

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

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

下策,改变了字段的类型

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

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

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

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