How to run laravel migration and DB seeder except one By Admin

I am having many migration and seeder files to run, Although I will need to run all files but currently I need to skip one migration and seeder.

How could I skip one file from laravel migration and db seeder command.

I do not want to delete files from the migrations or seeds folder to skip the file.

  •  Open
  •  27-07-2016
  •  7
  •  488

Answers ( 7 )

 Posted on 27-07-2016


2down vote

Skipping seeds are very simple, migrations not so much. To skip a seed, remove the following from your DatabaseSeeder class.


For migrations, There are three ways you can do it:

 Posted on 27-07-2016

Skipping seeds are very simple, migrations not so much. To skip a seed, remove the following from your DatabaseSeeder class.

For migrations, There are three ways you can do it:

Put the class you don't want to migrate into a different folder.
Insert your migrations into the database manually (Bindesh Pandya's answer elaborated).
Rename the file that you don't want to migrate to something like UsersTableMigration.dud.
Hope this helps

 Posted on 27-07-2016

From Laravel docs

By default, the db:seed command runs the DatabaseSeeder class, which may be used to call other seed classes. However, you may use the --class option to specify a specific seeder class to run individually
php artisan db:seed --class=UserTableSeeder
for migration, you will need to move the files to another folder (the ones you want to migrate) and specify path

php artisan migrate --path=database/migrations/temp

 Posted on 27-07-2016

I also faced the same problem in my project but after long time wasting in R & D i have found that Laravel does not provide any way to do this with migration and seeding but you have 2 ways to do this.

1) you'll save a lot of time just putting them into different folders. You could theoretically make your own artisan command that does what you want, or spoofs its by making directories, moving files, and running php artisan migrate.

For the seeders, just make a seeder and call the others seeders you want to run from with in it. Then just be explicit about what seeder you want to run. Try php artisan db:seed --help for more details there.

2) you can create a table Manually (which has same name as migration table is creating in you db) and insert the values of migration like this

insert into migrations(migration, batch) values('2015_12_08_134409_create_tables_script',1);
so migrate command will not create table which is already exist in migration table.

 Posted on 27-07-2016

If you want just omit (but keep) migration and seeder:

Rename your migration by removing .php extension: mv your_migration_file.php your_migration_file
Go to: DatabaseSeeder.php and comment out line with your unwanted seeder: //$this->call('YourSeeder');.
Run: php artisan migrate --seed
Execute below sql query on db (be careful, there should be migration file name WITHOUT extension) (this will prevent artisan migrate to execute your_migration_file in future):

INSERT INTO migrations (migration, batch) VALUES (your_migration_file, 1)
Rename back your migration file: mv your_migration_file your_migration_file.php
Uncomment your seeder in DatabaseSeeder.php
And you are done. Now when you run php artisan migrate any migration should be executed (except new one if you add some new migration files).

 Posted on 27-07-2016

just an idea comment seeder and schema. this is the way i guess


//Schema::create('users', function (Blueprint $table) {
          //  $table->increments('id');
          //  $table->string('name');
          //  $table->string('email')->unique();
          //  $table->string('password');
          //  $table->rememberToken();
           // $table->timestamps();
       // });
// Schema::drop('users');

 Posted on 27-07-2016

To directly answer your question, Laravel does not have a way to do this currently.

If I understand you correctly, I assume you're looking for a way to temporarily disable/skip a specific class from the default DatabaseSeeder.

You can easily create your own command which will accept a string such as a model/table name and attempt to run the migration and seed for that particular table. You will simply need something like the following:

public function handle(){ //fire for Laravel 4.*

    $tables = explode(',', $this->option('tables'));//default []
    $skip = explode(',', $this->option('skip'));//default [] 
    $migrations = glob("*table*.php");//get all migrations
    foreach($migrations as $migrate){
        //if tables argument is set, check to see if part of tables
        //if file name not like any in skip.. you get the point