如何在laravel 5迁移中添加表格的列而不丢失数据?
如何在laravel 5迁移中添加表格的列而不丢失数据?
我有一个现有的数据库表,我想在上面添加列。然而,当我运行php artisan migrate
命令时,它显示没有要迁移的内容。但我已经为添加表列添加了模式。我已经阅读了一些文章和链接,它们告诉我在添加新列之前应该先运行php artisan migrate:refresh
命令。问题是,这将删除我的现有数据表。有没有办法我可以执行迁移并成功地在我的表中添加列而不删除我的数据?请帮助我。非常感谢。这是我的迁移代码。
public function up() { // Schema::create('purchase_orders', function(Blueprint $table){ $table->increments('id'); $table->string('po_code'); $table->text('purchase_orders'); $table->float('freight_charge'); $table->float('overall_total'); $table->timestamps(); }); Schema::table('purchase_orders', function(Blueprint $table){ $table->string('shipped_via'); $table->string('terms'); }); } /** * Reverse the migrations. * * @return void */ public function down() { // Schema::drop('purchase_orders'); }
我想在我的purchase_orders
表中添加shipped_via
和terms
列。