Reputation: 939
after I've manually deleted a table in mysql, I run the command:
php artisan migrate
and I get this:
Nothing to migrate.
it only works the first time, how to re-run the migration in laravel?
Upvotes: 28
Views: 54432
Reputation: 180
The best thing you can do is drop the table from the database and then rename the migration last number and do
php artisan migrate
This doesn't recreate all the tables.
Upvotes: 2
Reputation: 581
You can simply do: php artisan migrate: fresh to re-migrate your migration and if you have seeder data then you simply do: php artisan migrate: fresh -- seed
Upvotes: 8
Reputation: 581
If you delete a table by hand, will have to delete the record from "migration" table too. This way when artisan migrate checks if your migration are not in "migration" table will migrate the unregistered ones.
Upvotes: 4
Reputation: 729
Laravel keeps a record of migrations that have been run. You need to go to the migrations table and delete the migration record. Laravel does this so that it knows which migrations have been run so that it doesn't run them again and so that in the case of a rollback, it knows the last batch of migrations which were done.
This may help https://laravel.com/docs/5.6/migrations
Upvotes: 33
Reputation: 206
That is the expected behaviour if you manually delete a table, because the previous batch migration job has already been deployed (in migrations table).
IF you want to re-migrate all the database, you can simply do: php artisan migrate:refresh
.
IF you want to make sure your database to be clean with your latest changes, you can drop your entire database tables and do php artisan migrate
again. Also, you can try php artisan migrate --seed
if you have any seeder.
Upvotes: 4
Reputation: 2532
Try composer dump-autoload
AND php artisan config:cache
if not working also Try php artisan migrate:refresh
.
OR Also Delete Migration table in database.
Upvotes: 16