laravel migration

create table

php artisan make:migration 文件描述 --create=表名

example: php artisan make:migration create_table_notes --create=notes

1202026-20181216103739383-84051155.png
1202026-20181216103804737-165283950.png


you can config table filed :

 public function up()
    {
        Schema::create('notes', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name');
            $table->string('gender');
            $table->string('events');
            $table->timestamps();
        });
    }

run : php artisan migrate
1202026-20181216105745767-1979869927.png
caused a error!!!
so you should edit
1202026-20181216105848654-1528765782.png
run again:
1202026-20181216105918557-1460854599.png
1202026-20181216105929747-291310312.png


you can rollback :

php artisan migrate:rollback

1202026-20181216110155722-1426814777.png

roll back all of your application's migrations:

php artisan migrate:reset 

rename table
Schema::rename($from,$to);

drop table
Schema::drop('users');
Schema::dropIfExists("users");

create Columns
Schema::table("users",function(Blueprint $table){
        $table->string('email');
})

reference:https://laravel.com/docs/5.7/migrations#creating-tables

1202026-20181216111438706-1083835687.png


drop columns
Schema::table('users',function(){
    $table->dropCloumn("name");
});

Reference :https://laravel.com/docs/5.7/migrations

转载于:https://www.cnblogs.com/cyany/p/10125953.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值