gpt4 book ai didi

laravel - 迁移 - 无法更改 double 据类型值

转载 作者:行者123 更新时间:2023-12-04 14:29:10 29 4
gpt4 key购买 nike

我有一个使用此迁移代码创建的现有表:

Schema::create('mytable', function (Blueprint $table) {

$table->increments('id');
$table->double('mycolumn',8,2)->unsigned()->default(0);
$table->timestamps();

});

然后我又创建了一个迁移文件来调整我的 mycolumn的值范围带有下面迁移文件的字段。
Schema::table('mytable', function (Blueprint $table) {

$table->double('mycolumn',15,2)->unsigned()->default(0)->change();

});

但是我收到一个错误:
In DBALException.php line 283:

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 li
st of all the known types with \Doctrine\DBAL\Types\Type::getTypesMap(). If this error occurs during database introspection then you might have forgott
en to register all database types for a Doctrine Type. Use AbstractPlatform#registerDoctrineTypeMapping() or have your custom types implement Type#getM
appedDatabaseTypes(). If the type name is empty you might have a problem with the cache or forgot some mapping information.

我错过了什么?

最佳答案

您在 documentation 中遗漏了这个

Only the following column types can be "changed": bigInteger, binary, boolean, date, dateTime, dateTimeTz, decimal, integer, json, longText, mediumText, smallInteger, string, text, time, unsignedBigInteger, unsignedInteger and unsignedSmallInteger.



所以 无法更改。

我还没有尝试过,但您可以使用这样的 RAW MySQL 查询,当然首先在本地尝试:
DB::statement('alter table mytable modify mycolumn DOUBLE(15,2) DEFAULT 0');

关于laravel - 迁移 - 无法更改 double 据类型值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56864556/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com