I have column balance
with data type double
, but I want to change it for storing price in proper way. I want to make it decimal
.
For that I am trying I am doing following
public function up()
{
Schema::table('billing', function (Blueprint $table) {
//
$table->decimal('balance', 8, 2)->change();
});
}
But I am confused about down function, should I revert it back, I mean the previous data type?
Can someone kindly guide me about that, I will be thank full. Thank you
$table->unique('slug'); So you add unique index to existing 'slug'.
The various approaches to solving the Set Default Value For Column In Laravel Model problem are summarised in the following code. You can use change() method: Schema::table('users', function ($table) { $table->integer('active')->default(0)->change(); });
First of all we need to install "doctrine/dbal" composer package. After successfully install composer package we can change data type and change column name using migration. * Run the migrations. * Reverse the migrations.
You don't need to define a drop function for an up function which alters a column.
Because drop()
is intended to delete a table and maybe cascade the action.
And your initial billing
migration file should already have a drop definition for deleting that table.
So you can safely keep the down()
function empty in your new migration file
The purpose of down method is to revert the change to state which was exactly same before running the up method of migration.If you are changing any user type in up() then it should be reverse in down() ideally.So your migration will end like this:
public function up()
{
//double to decimal
}
public function down()
{
//decimal to double
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With