Safely remove migration In Laravel

前端 未结 9 1761
天涯浪人
天涯浪人 2021-01-29 17:46

In Laravel, there appears to be a command for creating a migration, but not removing.

Create migration command:

php artisan migrate:make create_users_tab         


        
相关标签:
9条回答
  • 2021-01-29 18:12

    I accidentally created a migration with a bad name (command: php artisan migrate:make). I did not run (php artisan migrate) the migration, so I decided to remove it. My steps:

    1. Manually delete the migration file under app/database/migrations/my_migration_file_name.php
    2. Reset the composer autoload files: composer dump-autoload
    3. Relax

    If you did run the migration (php artisan migrate), you may do this:

    a) Run migrate:rollback - it is the right way to undo the last migration (Thnx @Jakobud)

    b) If migrate:rollback does not work, do it manually (I remember bugs with migrate:rollback in previous versions):

    1. Manually delete the migration file under app/database/migrations/my_migration_file_name.php
    2. Reset the composer autoload files: composer dump-autoload
    3. Modify your database: Remove the last entry from the migrations table
    0 讨论(0)
  • 2021-01-29 18:13
     php artisan migrate:fresh
    

    Should do the job, if you are in development and the desired outcome is to start all over.

    In production, that maybe not the desired thing, so you should be adverted. (The migrate:fresh command will drop all tables from the database and then execute the migrate command).

    0 讨论(0)
  • 2021-01-29 18:14

    This works for me:

    1. I deleted all tables in my database, mainly the migrations table.
    2. php artisan migrate:refresh

    in laravel 5.5.43

    0 讨论(0)
提交回复
热议问题