Hi,
I'm working on a big project and have created a lot of migrations. The problem is that I didn't find any way to run a specific migration e.g. by migration name, like we can do in database seeds where we add the --class=seeder_name. I think there should be a way to do this. Please help me someone.
I think migrations are designed to run sequentially as each one could depend on an earlier one.
For example, migration#1 could create a table and migration#2 could add some extra fields to that table. 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.
Thanks. I know this but I have different migration files for different tables and imagine I have 10 migration files and I want to run migration file #6 which I changed to add a column to a specific table. I don't want to create an additional migration file to just do this little change but I want to be able to make changes in the migration files and run them separately by name or date.
I get your use case but I think the methodology behind migrations would mean that you would have to create an additional migration or rollback to migration #5, change #6 and then migrate from there.
I have same problem and not found how can be done using command line . Very strange because this is regular task for one developer. My way is to open "migrations" table and delete migration i want to be rerun , after that i just do "php artisan migrate" and here we go , migration is restarted again.
I have a solution for the rare cases that you only want to run a specific migration. It's a bit of a "hack", but you can accomplish this by going into your database and updating the "migrations" table to show that all migrations, other than the one that you want to run, have already been completed. You do this by simply inserting a row for each migration that you DONT want to run, and then set a batch number as the next sequential number that had not yet been run. This worked for me in a case where I had pulled some work onto a local machine and one of the migrations had a conflict with my local database. I simulated as if the troublesome migration had been completed already, and then ran artisan migrate. Worked like a charm! Hope this helps.
Here is my solution (Laravel 5.3):
php artisan migrate --pretend
copy the SQL queries and paste them in your db tool of choice (phpMyAdmin, HeidiSQL etc.)
I've recently run into a situation where a migration didn't run in a batch - it's in the migrations table, but the commands from it weren't run (I've run into this situation when an add index operation fails on table that contains lots of data - the migration is considered succesful, even though not all operations were such)
In this situation there's really no way around it - copying the migration to another folder and rerunning on given path doesn't work, as the name of migration is compared, not entire path. --pretend doesn't work as well, as it first compares if migration has been run.
What I've had to do is delete the migration from migrations table, and then rerun it manually.
Just had the same issue and what I did was I've create a 'temp' folder inside 'migrations' folder. Then I moved the migrations I wanted untouched into it and left only the ones I wanted to migrate. After the migration I simply moved back the migrations from the temp folder to migrations folder. Not that fancy but It worked for me.
The most useful tip here is that 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.
I had the same issue and I was constantly facing the same issue and this is because of foreign key constraints which is you want to create a relation with a table which hasn't yet created and all the migration files are executed in sequence.
and what I did " Just renamed the file to change the order and made a sequence that all those table who are creating a relations with the other tables must be on the lower order" and at last resolved my issue.
Thanks.
If you delete table and the migration from the migrations table in your database for the table you wish to migrate again, then php artisan migrate will work and just create the table again. I don't know if this has any undesirable side effects.
For what it's worth, everything seems to work just fine!, however, would be interested to know if this is problematic if anyone knows?
to delete the entries in the migrations table on the database.
From there you can edit the files in the migrations directory.
then run a php artisan migrate:status - You should notice that the specific migrations that are deleted from the DB show "No" under "Ran?" column.
php artisan migrate
Every other option I saw was wiping data, and that was not my use case.
Also took forever to recall this command 'php artisan migrate --pretend' which shows you what would happen in the event you run the migrate... great tool.