Reputation: 106
I ran php artisan migrate:rollback
on command line, so the migration deleted ALL TABLES in db.
There is only one migration created but have others tables in used db.
The laravel documentation says:
To drop an existing table, you may use the
drop
ordropIfExists
methods.
and the function down()
on migration code is the default like as bellow:
public function up()
{
Schema::create('products', function (Blueprint $table) {
$table->bigIncrements('id');
$table->integer('image')->unsigned()->nullable();
$table->string('name', 64);
$table->string('slug', 64)->unique();
$table->integer('price')->unsigned();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('products');
}
}
I don't think the Schema::dropIfExists('products')
work properlly in this case, this is a bug? or my(and laravel documentation) mistake?
Upvotes: 0
Views: 4489
Reputation: 49
I know this post is over a year old, but this might help others who are having this issue and are looking for a solution. I'm guessing what happened here is if you run php artisan migrate:rollback
it will rollback all migrations from the last batch. In other words, it wil run all down()
functions in all the migrations in the same batch. So if you have made a down()
function in those migrations where you revert the changes (deleting the created table), those will be ran as well.
To prevent this, you can add the --step
parameter to indicate how many migrations should be rolled back, like so: php artisan migrate:rollback --step=1
. Then only your last migration will be rolled back.
Upvotes: 0
Reputation: 1138
Roll back, rolls back each migration of the last batch.
If your all migration in same batch then it will rollback all the migrations. So your all tables will be deleted from the database.
Upvotes: 1