0

I want to rename the column in database using migration, but when i tried it, the datatype also changes. How to rename column without changing the data type.

The current name of the column in the database is payment_amount_cash and its type is double(10,2)

I tried

$table->renameColumn('payment_amount_cash', 'payment_amount_full')->comment('Advanced payment')->default("0.00");

to rename the column. Then after migration, the name was changed but the data type was also changed from double(10,2) to only double thus, making the default value change from 0.00 to 0.

I also tried to change the data type after the schema of renaming the column.

$table->renameColumn('payment_amount_cash', 'payment_amount_full')->comment('Advanced payment')->default("0.00");
$table->double('payment_amount_full', 10,2)->change();

but this one gives me error upon migration.

 Doctrine\DBAL\DBALException  : Unknown column type "double" requested.
 Any Doctrine type that you use has to be registered with \Doctrine\DBAL\Types\Type::addType(). 
You can get a list of all the known types with \Doctrine\DBAL\Types\Type::getTypesMap(). 
If this error occurs during database introspection then you might have forgotten to register all database types for a Doctrine Type. 
Use AbstractPlatform#registerDoctrineTypeMapping() or have your custom types implement Type#getMappedDatabaseTypes(). 
If the type name is empty you might have a problem with the cache or forgot some mapping information.

With this, I just want to know how to rename the column without affecting the data type. After migration, I would like to retain the data type of the column I just changed the name.

MDB
  • 339
  • 4
  • 19

1 Answers1

0

I learned that there is an issue in Schema regarding the enum and still in discussion until now. I just used the other way to update the datatype of the column.

DB::statement('ALTER TABLE reservations MODIFY COLUMN payment_amount_full double(10,2)');

and this works for me. If there are other ways on how to do this, please let me know. Thanks.

MDB
  • 339
  • 4
  • 19