Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 5 - skip migrations

Tags:

I have migrated an existing Laravel 5 application and database. Only no migrations table was there yet, so I created this with the following command:

php artisan migrate:install 

Inside the database migration folders three files exist (2015_12_08_134409_create_tables_script.php, 2015_12_08_134410_create_foreign.php, 2015_12_08_134411_create_index.php)

When using 'php artisan migrate' the scripts inside the migrations folder are executed again. This is what I want to avoid. Is it possible to insert records in Laravel's migrations table, so these scripts will be skipped and new scripts will be picked up once 'php artisan migrate' is executed again?

like image 743
Erhnam Avatar asked Jan 31 '16 15:01

Erhnam


People also ask

Is migration necessary in Laravel?

for testing/seeding, migration to another database or creating new local setup), then it is not necessary. Also models are not required but if you want to use Eloquent and other fancy Laravel things, then create them.

How do I add a column in Laravel migration without losing data?

Show activity on this post. This way a new migration file will be created. Set your column details there, run the migrations using php artisan migrate and that's all. You'll have this new column in your users table without losing previously stored data.

How do I refresh a specific migration?

* To run a specific migration php artisan migrate:refresh --path=/database/migrations/2019_03_23_165757_create_combined_1553343771_users_table. php - Note: it will drop the table and create a new one.


1 Answers

Once you have the migration table created, insert these records:

insert into migrations(migration, batch) values('2015_12_08_134409_create_tables_script',1); insert into migrations(migration, batch) values('2015_12_08_134410_create_foreign',1); insert into migrations(migration, batch) values('2015_12_08_134411_create_index',1); 

So artisan will understand those migrations as 'executed'

like image 107
Sergio Guillen Mantilla Avatar answered Nov 30 '22 22:11

Sergio Guillen Mantilla