maxehnert's avatar

How to remove migration from queue?

I am having trouble with conflicting data. When I run php artisan migrate:status I get this back:

`+------+-------------------------------------------------+

| Ran? | Migration |

+------+-------------------------------------------------+

| N | 2014_1012000000_create_users_table |

| N | 2014_10_12_100000_create_password_resets_table |

| N | 2015_03_13_132311_create_articles_table |

| N | 2015_03_13_133120_add_excerpt_to_articles_table |

| N | 2015_03_13_134007_create_articles_table |

+------+-------------------------------------------------+`

I need to remove one or both of the create_articles_table migrations before I can do anything. Even using a --force flag doesn't work. At this time, none of these are populating in my project in the database/migration folder so I can't find how to access them.

Tried running this $composer dump-autoload hoping that would help but it isn't

Generating autoload files Warning: Ambiguous class resolution, , "CreateArticlesTable" was found in both <filename> and <filename> , the first will be used.

What led up to this was lots of conflicting errors and I was stuck where I couldn't add or rollback anything so I decided to go into mysql command and remove the articles table completely and delete the files from the migrations folder. I then went back to mysql and created the articles table and tried to run some migrate commands but still nothing is auto populating in the folder. It's stuck in this limbo where I I can't figure out how to remove an object from the list.

0 likes
8 replies
RavanScafi's avatar

If you clean your database from MySQL and then just delete one of the article migrations, you'll be good to go. A simple php artisan migrate will regenerate tables structure.

sitesense's avatar

Take a look at the migrations table in your database. It appears that you might have renamed some of your migrations and this may not line up with what you have in the db. You can probably just delete all the records in the migrations table and start again.

maxehnert's avatar

@sitesense

This is what I get when I check the migrations table

mysql> show fields from migrations;

+-----------+--------------+------+-----+---------+-------+

| Field     | Type         | Null | Key | Default | Extra |

+-----------+--------------+------+-----+---------+-------+

| migration | varchar(255) | NO   |     | NULL    |       |

| batch     | int(11)      | NO   |     | NULL    |       |

+-----------+--------------+------+-----+---------+-------+

Is there another level down I can look in because this is all I can get to show up.

I think because I ran reset or maybe refresh it rolled back the user tables and articles table, as noted in the first post. so when I look in homestead now I get this:

mysql> show tables;

+---------------------+

| Tables_in_homestead |

+---------------------+

| migrations          |

+---------------------+
sitesense's avatar

All that looks fine.

You should be able to delete one of your ...create_articles_table migrations and you should be good to go.

Is that not the case?

maxehnert's avatar

I may be able to, but I am pretty new to this and I don't think I know the right command to use to execute this. Should it be something like this? mysql> drop table migrations.2015_03_13_134007_create_articles_table; this doesn't work, but just wondering if I'm on the right track.

maxehnert's avatar

Thank you. Now I ran that, and rechecked and it was gone. Then I ran

php artisan migrate:status
No migrations found.

however when I tried to create the migrations table again it brought back all the old migrations. I figured they would all be destroyed.

$ php artisan migrate
Migration table created successfully.
PHP Fatal error:  Cannot redeclare class CreateArticlesTable

checking what is in the queue and it shows them all back again.

$ php artisan migrate:status
+------+-------------------------------------------------+
| Ran? | Migration                                       |
+------+-------------------------------------------------+
| N    | 2014_10_12_000000_create_users_table            |
| N    | 2014_10_12_100000_create_password_resets_table  |
| N    | 2015_03_13_132311_create_articles_table         |
| N    | 2015_03_13_133120_add_excerpt_to_articles_table |
| N    | 2015_03_13_134007_create_articles_table         |
+------+-------------------------------------------------+
michaeldyrynda's avatar

The migrations table in yor database shows the migrations that have already been run. This is so that Laravel knows which migrations and in what order it needs to run them back in.

php artisan migrate:status will compare what is in the database vs what is in the filesystem and show you the differences between the two as pending migrations.

If you have a pending migration that you want to remove, just move or delete the relevant migration file from the database/migrations folder in your app.

The problem in running your migrations is that you have two identically named classes, hence the redeclaration error. You'll need to either remove the second one or - if you need the fields from the second migration - merge the two migration files into one and try running the migration again.

Please or to participate in this conversation.