如何在数据库中存在的自定义列之后添加新列
How to add new column after a custom column existing at the DB
我想在自定义列之后添加带有迁移的新列,例如我有这个 table 结构:
Table Screenshot
现在我需要在 prd_description
(第 14 列)之后添加一个名为 badge
的新列。
所以我运行php artisan make:migration add_badge_to_products_table --table=products
这里是:
public function up()
{
Schema::table('products', function (Blueprint $table) {
$table->tinyInteger('badge')->unsigned()->nullable();
});
}
但现在的问题是,我不知道如何在该特定列之后添加该列。因为默认情况下,Laravel 在 table.
的末尾添加了这个
那么怎么做呢?
在单个特定列之后添加列喜欢,
Schema::table('products', function (Blueprint $table) {
$table->tinyInteger('badge')->after('prd_description')->unsigned()->nullable();
});
也像这样添加多列,
https://laravel.com/docs/8.x/migrations#column-order
你需要使用下面的after方法
public function up()
{
Schema::table('products', function (Blueprint $table) {
$table->tinyInteger('badge')->unsigned()->nullable()->after('prd_description');
});
}
我想在自定义列之后添加带有迁移的新列,例如我有这个 table 结构:
Table Screenshot
现在我需要在 prd_description
(第 14 列)之后添加一个名为 badge
的新列。
所以我运行php artisan make:migration add_badge_to_products_table --table=products
这里是:
public function up()
{
Schema::table('products', function (Blueprint $table) {
$table->tinyInteger('badge')->unsigned()->nullable();
});
}
但现在的问题是,我不知道如何在该特定列之后添加该列。因为默认情况下,Laravel 在 table.
的末尾添加了这个那么怎么做呢?
在单个特定列之后添加列喜欢,
Schema::table('products', function (Blueprint $table) {
$table->tinyInteger('badge')->after('prd_description')->unsigned()->nullable();
});
也像这样添加多列, https://laravel.com/docs/8.x/migrations#column-order
你需要使用下面的after方法
public function up()
{
Schema::table('products', function (Blueprint $table) {
$table->tinyInteger('badge')->unsigned()->nullable()->after('prd_description');
});
}