If you've only created the migration and you've not executed the php artisan migrate command, all you would need to do to remove the migration is to delete the file. You could do that via your text editor or the command line with the rm command.
Delete your Migrations folder. Create a new migration and generate a SQL script for it. In your database, delete all rows from the migrations history table. Insert a single row into the migrations history, to record that the first migration has already been applied, since your tables are already there.
You can use the truncate() function in a migration to remove all rows and reset any auto increment fields.
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
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.
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).
You likely need to delete the entry from the migrations table too.
DO NOT run php artisan migrate:fresh
that's gonna drop all the tables
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With