gpt4 book ai didi

php - 使用 laravel 在字段模式迁移中定义属性 zerofill 和大小

转载 作者:行者123 更新时间:2023-12-05 08:27:37 26 4
gpt4 key购买 nike

如何使用 Laravel 在字段模式迁移中定义属性 zerofill 和大小 (2)?

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

这个字段用 zerofill。

我想使用我的播种机:

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

最佳答案

Zerofill 不是 SQL 标准。 laravel 的 shema builder 只提供这些 ANSI SQL 标准。

但是您可以使用一种变通方法来使用原始 sql 语句定义它:

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');

关于php - 使用 laravel 在字段模式迁移中定义属性 zerofill 和大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35108133/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com