Add a new column to existing table in a migration

前端 未结 12 2618
离开以前
离开以前 2020-11-28 17:09

I can\'t figure out how to add a new column to my existing database table using the Laravel framework.

I tried to edit the migration file using...



        
12条回答
  •  -上瘾入骨i
    2020-11-28 17:59

    First you have to create a migration, you can use the migrate:make command on the laravel artisan CLI.Old laravel version like laravel 4 you may use this command for Laravel 4:

    php artisan migrate:make add_paid_to_users
    

    And for laravel 5 version

    for Laravel 5+:

    php artisan make:migration add_paid_to_users_table --table=users
    

    Then you need to use the Schema::table() . And you have to add the column:

    public function up()
    
    {
    
        Schema::table('users', function($table) {
    
            $table->integer('paid');
    
        });
    
    }
    

    further you can check this

提交回复
热议问题