【发布时间】:2020-01-13 22:54:51
【问题描述】:
我想使用迁移重命名数据库中的列,但是当我尝试它时,数据类型也发生了变化。如何在不更改数据类型的情况下重命名列。
数据库中列的当前名称是 payment_amount_cash,其类型为double(10,2)
我试过了
$table->renameColumn('payment_amount_cash', 'payment_amount_full')->comment('Advanced payment')->default("0.00");
重命名列。然后在迁移之后,名称发生了变化,但数据类型也从 double(10,2) 更改为仅 double 从而使默认值从 更改0.00 到 0。
我也尝试在重命名列的架构后更改数据类型。
$table->renameColumn('payment_amount_cash', 'payment_amount_full')->comment('Advanced payment')->default("0.00");
$table->double('payment_amount_full', 10,2)->change();
但是这个在迁移时给了我错误。
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.
有了这个,我只想知道如何在不影响数据类型的情况下重命名列。迁移后,我想保留刚刚改名的列的数据类型。
【问题讨论】:
标签: laravel-5.8 laravel-migrations