codeGentry

107 经验值

--------------+------------------+------+-----+---------------------+----------------+
| Field        | Type             | Null | Key | Default             | Extra          |
+--------------+------------------+------+-----+---------------------+----------------+
| id           | int(10) unsigned | NO   | PRI | NULL                | auto_increment |
| Article_id   | bigint(20)       | NO   |     | NULL                |                |
| extend_key   | varchar(255)     | NO   |     | NULL                |                |
| extend_value | text             | NO   |     | NULL                |                |
| published_at | timestamp        | NO   |     | 0000-00-00 00:00:00 |                |
| created_at   | timestamp        | NO   |     | 0000-00-00 00:00:00 |                |
| updated_at   | timestamp        | NO   |     | 0000-00-00 00:00:00 |                |
| flag         | tinyint(4)       | NO   |     | 1                   |                |
+--------------+------------------+------+-----+---------------------+----------------+

解决了。

废话不多说,demo代码如下:

public function up()
{
    Schema::create('ArticleExtend', function (Blueprint $table) {
        $table->increments('id');
        $table->string('extend_key');
        $table->text('extend_value');
        $table->timestamp('published_at');
        $table->timestamps();
        $table->tinyInteger('flag');
    });
}

找了找文档,类似tinyInteger的函数中,没有用于设置默认值的参数也没有看到Scheam里有default字眼的函数。请问如何给字段设置默认值呢?@JellyBool