且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用laravel 5迁移在表中添加列而不丢失其数据?

更新时间:2023-12-01 10:40:40

使用以下命令修改现有表

Use below command to modify the existing table

php artisan make:migration add_shipped_via_and_terms_colums_to_purchase_orders_table --table=purchase_orders

使用--create创建新表,并使用--table修改现有表.

use --create for creating the new table and --table for modifying the existing table.

现在将创建一个新的迁移文件.在此文件的up()函数内部,添加以下行

Now a new migration file will be created. Inside the up() function in this file add these line

Schema::table('purchase_orders', function(Blueprint $table){
    $table->string('shipped_via');
    $table->string('terms');
});

然后运行php artisan migrate