Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel change migration order

Is there a way how I can change the migrations order without remaking them all? Because now I have a problem with my foreign keys -_- (working with laravel)

like image 704
Jamie Avatar asked Sep 11 '15 12:09

Jamie


People also ask

What is up and down in Laravel migration?

A migration class contains two methods: up and down . The up method is used to add new tables, columns, or indexes to your database, while the down method should reverse the operations performed by the up method.


1 Answers

  1. Roll back all the migrations (or start with a fresh database);

  2. Change the dates that form the first part of the migration filenames so they're in the order you want (eg. for 2014_06_24_134109_update_database.php, the date & time is 2014-06-24, 13:41:09);

  3. Run the migrations again.

With respect to your comment about foreign keys... I'm not sure that the problem is with Laravel. More likely, it's just MySQL.

I avoid foreign keys because once you get a moderately complicated set of relations, you start to run into problems with database consistency like you're seeing - it's hard for the server to figure out what order to create the tables & relationships in, and it starts to cause difficulties with things like dump files (for backups).

like image 139
Kryten Avatar answered Sep 28 '22 05:09

Kryten