如何用 migrate 修改字段的 defalut 值

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

如下并不行:

$table->tinyInteger('examine')->default(0)->change();
《L01 基础入门》
我们将带你从零开发一个项目并部署到线上,本课程教授 Web 开发中专业、实用的技能,如 Git 工作流、Laravel Mix 前端工作流等。
《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,你这种字段类型不能这样修改吧。

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年前 评论

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