[英]How to add drop-down list & toggle switch columns into migration table columns in PHP Laravel?
[英]Laravel: How to create migration file for drop multiple columns from a table?
當我刪除一列時,我使用以下命令創建遷移文件,
php artisan make:migration drop_institue_id_column_from_providers
和遷移文件:
public function up()
{
Schema::table('providers', function(Blueprint $table) {
$table->dropColumn('institue_id');
});
}
public function down()
{
Schema::table('providers', function (Blueprint $table)
{
$table->integer('institue_id')->unsigned();
});
}
如果我想刪除多個列,我可以這樣寫遷移文件,
public function up()
{
Schema::table('providers', function(Blueprint $table) {
$table->dropColumn('institue_id');
$table->dropColumn('institue_name');
$table->dropColumn('institue_address');
});
}
public function down()
{
Schema::table('providers', function (Blueprint $table)
{
$table->integer('institue_id')->unsigned();
$table->char('institue_name');
$table->char('institue_address');
});
}
但是創建該遷移文件的命令是什么? 謝謝你。
我認為這只是關於遷移類的命名約定的問題。
如果是這樣,那么 file\\class 被稱為什么並不重要,只要它讓您對它的作用有一個很好的了解。
所以它可能是這樣的:
php artisan make:migration drop_institue_columns_from_providers
當您執行php artisan make:migration
命令時,它只會創建一個類,您可以在其中指定您可以執行的遷移。 您可以對一張表進行多次修改,甚至可以對多張表進行修改。 所以只需將所有代碼放在一個遷移文件中就可以了。
要創建遷移文件,請運行:
php artisan make: migration your_migration_file_name_here
然后你可以通過傳遞一個數組來刪除多列
Schema::table('providers', function(Blueprint $table) {
$table->dropColumn('institue_id', 'institue_name', 'institue_address');
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.