Eli*_*Eli 17 php migration postgresql laravel-5.2
我有一个现有的数据库表,我想在其上添加列.但是,当我运行php artisan migrate
命令时,它没有说任何迁移.但是我已经添加了一个用于添加表列的Schema.我已经阅读了一些文章和链接,我应该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');
}
Run Code Online (Sandbox Code Playgroud)
我想添加列shipped_via
,并terms
在我的purchase_orders
表.
Abh*_*hek 35
使用以下命令修改现有表
php artisan make:migration add_shipped_via_and_terms_colums_to_purchase_orders_table --table=purchase_orders
Run Code Online (Sandbox Code Playgroud)
使用--create
创建新表和--table
修改现有的表.
现在将创建一个新的迁移文件.up()
在此文件中的函数内添加这些行
Schema::table('purchase_orders', function(Blueprint $table){
$table->string('shipped_via');
$table->string('terms');
});
Run Code Online (Sandbox Code Playgroud)
然后运行 php artisan migrate