How can I modify a migration in Laravel?

前端 未结 5 620
眼角桃花
眼角桃花 2020-12-29 23:49

I\'m trying to modify a existing migration. Here is my current migration class:

class CreateLogForUserTable extends Migration
{
    public function up()
             


        
5条回答
  •  春和景丽
    2020-12-30 00:21

    There is one more option. Roll back the migration, edit the file, and run it again.

    This is a fairly common thing to do on a local development server while you're working out the bugs in a new piece of code. Using the method from the accepted answer, you might end up with 17 migrations for creating a single table!

    php artisan migrate
    # realize you've made an error
    php artisan migrate:rollback
    # edit your migration file
    php artisan migrate
    

    The number of steps back to take can be specified on the command line if needed.

    # undo the last 3 migrations
    php artisan migrate:rollback --step=3
    

    Or you can specify a particular migration that needs undoing.

    # undo one specific migration
    php artisan migrate:rollback --path=./database/migrations/2014_10_12_100000_create_users_table.php
    

提交回复
热议问题