使用laravel在字段模式迁移中定义属性zerofill和大小 [英] Define property zerofill and size on field schema migration with laravel

查看:176
本文介绍了使用laravel在字段模式迁移中定义属性zerofill和大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在使用Laravel进行字段模式迁移时定义属性zerofill和size(2)?

How can I define property zerofill and size (2) on field schema migration with Laravel?

Schema::create('books', function (Blueprint $table) {
    $table->integer('reference')->length(2);
});

,该字段为零填充.

我想使用播种机:

public function run()
{
    Book::create
    ([
        'reference' => 01
    ]);
}

推荐答案

Zerofill不是SQL标准. laravel的shema构建器仅提供这些ANSI SQL标准.

Zerofill is not a SQL standard. The shema builder of laravel provides only these ANSI SQL standards.

但是您可以使用变通方法通过原始sql语句进行定义:

But you can use a workaround to define it with a raw sql statement:

create_books.php

create_books.php

Schema::create('books', function (Blueprint $table) {
    $table->integer('reference');
});
DB::statement('ALTER TABLE books CHANGE reference reference INT(2) UNSIGNED ZEROFILL NOT NULL');

这篇关于使用laravel在字段模式迁移中定义属性zerofill和大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆