In Laravel, there appears to be a command for creating a migration, but not removing.
Create migration command:
php artisan migrate:make create_users_table
If I want to delete the migration, can I just safely delete the corresponding migrations file within the database/migrations folder?
Migrations file:
2013_05_31_220658_create_users_table
If the migration has been run (read: migrated) then you should roll back your migration to clear the history from your database table. Once you're rolled back you should be able to safely delete your migration file and then proceed with migrating again.
I accidentally created two times create_users_table. It overrided some classes and turned rollback into ErrorException.
What you need to do is find autoload_classmap.php in vendor/composer folder and look for the specific line of code such as
and edit path. Then your rollback should be fine.
I will rather do it manually
...database/migrations
folderphp artisan migrate
, log into your phpmyadmin or SQL(whichever the case is) and in your database, delete the table created by the migrationWorks for me, hope it helps!
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:app/database/migrations/my_migration_file_name.php
composer dump-autoload
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):app/database/migrations/my_migration_file_name.php
composer dump-autoload
This works for me:
php artisan migrate:refresh
in laravel 5.5.43
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).