Lea*_*ner 3 php migration laravel laravel-5
我正在使用Laravel 5.3,我想在表迁移中将字段定义为可空和无符号.由于两者都是索引修饰符,我可以在串联中使用它们吗?喜欢:
$table->integer('some_field')->unsigned()->nullable();
Run Code Online (Sandbox Code Playgroud)
如果在laravel文档或某处进行了这些修改,还请提供一些参考.
请注意,我想将up()函数中的字段定义为无符号和可空.我不想要具有以下down()功能的解决方案:
public function up()
{
Schema::create('ex', function (Blueprint $table) {
$table->integer('some_field')->unsigned();
});
}
public function down()
{
DB::statement('ALTER TABLE ex MODIFY `some_field` integer NOT NULL;');
}
Run Code Online (Sandbox Code Playgroud)
提前致谢!
你可以做
Schema::create('ex', function (Blueprint $table) {
$table->integer('some_field')->unsigned()->nullable();
});
Run Code Online (Sandbox Code Playgroud)
你可以。Laravel 允许大量方法链接。每个列方法都定义为返回相同的Blueprint对象,因此您可以轻松地调用它的另一个方法。这意味着您甚至可以这样做:
Schema::create('ex', function (Blueprint $table) {
$table->integer('some_field')->unsigned()->default(10);
});
Run Code Online (Sandbox Code Playgroud)
一切都会好起来的:)
有关更多信息,请参阅有关数据库迁移的文档(请参阅“列修饰符”部分)。
| 归档时间: |
|
| 查看次数: |
9954 次 |
| 最近记录: |