200

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?

Ravindra Bhanderi
  • 2,478
  • 4
  • 17
  • 29
Keval Mangukiya
  • 2,243
  • 2
  • 11
  • 13

1 Answers1

479

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.

lewis4u
  • 14,256
  • 18
  • 107
  • 148
Ravi Thummar
  • 5,048
  • 1
  • 11
  • 22
  • 5
    Add the `.php` extension in `path` like `php artisan migrate --path=/database/migrations/my_migrations.php` – Sherin Jose Dec 26 '18 at 07:49
  • 34
    Showed `Nothing to migrate.` to me. Why? Does the migration need to be already on the migrations tables? I tried with one already there too and it gave the same thing. Is this path my full path to the file or is it relative to my app's root? Edit: also tried with the full path and it says the same thing. – giovannipds Jan 11 '19 at 13:49
  • 8
    Specifying `--path=path/to/specific_migration` didn't work for me, I had to adopt the other strategy of moving the specific files into a subfolder, then run `--path=path/to/subfolder`, it is a big shortcoming. Watch out though: `migrate:reset` will ignore --path ! – Fabien Haddadi Feb 07 '19 at 06:08
  • 6
    Shows 'Nothing to migrate'. – davefrassoni May 22 '19 at 22:46
  • 1
    I think this only works with later Laravel version (5.X). It worked for me – Delmontee Aug 26 '19 at 11:08
  • Moving file to subfolder was the solution for me. – ako Sep 28 '19 at 10:33
  • 2
    this will work if the migration already not in migrations table. if migrations table contain this migration then remove and run command again – Emtiaz Zahid Nov 15 '19 at 11:04
  • 2
    If, you want to delete and create the table, again use: ` php artisan migrate:refresh --path=/database/migrations/file_name.php` – gdfgdfg Dec 10 '19 at 11:01
  • 2
    Another option is to remove the migration that ran from the migrations table, then run `php artisan migrate` and it'll run that one you just removed. – TheTC Dec 26 '19 at 14:48
  • 38
    Instead of only `migrate` use `migrate:refresh`, that'll work. For example, it will be `php artisan migrate:refresh --path=/database/migrations/my_migrations.php` – virajs0ni Mar 13 '20 at 13:55
  • It did not work for me when I created the migration file manually. It worked when I did it via `php artisan make:migration migration-name-here` – padawanTony Mar 15 '20 at 18:09
  • you just need to execute "php artisan migrate" , Laravel knows which files already been executed and only run the latest – Julios_Rodmax Nov 17 '20 at 03:47
  • 1
    If you are using gitbash, it will not work. Try with cmd. – RunningAdithya Nov 27 '20 at 12:45
  • 3
    `migrate:refresh` is BAD. Laravel will DROP ALL TABLES at first. – Han Tran Sep 13 '21 at 00:17
  • 1
    Don't use refresh because it creates the risk of overriding all the existing data. The marked answer is incorrect. – techwestcoastsfosea Nov 25 '21 at 23:10
  • If it says file not found add a dot `.` immediately after `--path=` i.e. `php artisan migrate --path=./database/migrations/full_migration_file_name.php` – John Feb 21 '22 at 15:05
  • BEWARE OF USING "migrate:refresh" in production, will drop all of your data! – Dr4v Jul 07 '22 at 19:37
  • If it says `Nothing to migrate`, check out your `migrations` table and delete any entry about the migration you're trying to run. – SaladeDeFruits Jan 22 '23 at 16:04