I create on address table migration but one migration is already in the database it gives following error :
Base table or view already exists: 1050 Table 'notification' already exists
So, Can I run specific migration? How can I run in Laravel?
To run the specific migration in Laravel, you need to use --path option with the php artisan migrate command. Let's take a simple example, we have '2019_12_04_131405_create_payments_table. php' migration in the database/migrations directory and we would like to run this migration.
If you tried to run migration#2 without every having run #1 then it would fail. When you run artisan migrate then it will only run migrations that haven't already been applied unless you use migrate:refresh in which case it will reset and re-run all migrations.
To run a specific migration up or down, use db:migrate:up or db:migrate:down . The version number in the above commands is the numeric prefix in the migration's filename. For example, to migrate to the migration 20160515085959_add_name_to_users. rb , you would use 20160515085959 as the version number.
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.
TLDR;
"By the book":
If there are already migrated tables and there is some data stored in those tables, be careful with php artisan migrate:refresh
. You will lose all your data!
For this specific question OP has already run the migration and by the book if he wants to run the same migration again, then first he should rollback with php artisan migrate:rollback
. This will undo the last migration/s.
Then you can run php artisan migrate
and all NOT migrated migrations will be migrated.
If you created more migrations and they are not migrated yet, to run only a specific migration use this:
php artisan migrate --path=/database/migrations/full_migration_file_name_migration.php
And sometimes if there is something messed up and you get errors on migrate, saying that the table already exists you can manually delete that specific entry from migrations
AND the table which causes the problem in your DB and run php artisan:migrate
to recreate the table.
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