且构网

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

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

更新时间:2023-12-01 09:04:52

使用以下命令修改现有表

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