laravel - 迁移 - 无法更改双精度数据类型值
问题描述
我有一个使用此迁移代码创建的现有表:
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.
我错过了什么?
解决方案
您在文档中缺少此内容
只有以下列类型可以“更改”:bigInteger、binary、boolean、date、dateTime、dateTimeTz、decimal、integer、json、longText、mediumText、smallInteger、string、text、time、unsignedBigInteger、unsignedInteger 和 unsignedSmallInteger。
所以double不能改变。
我没有尝试过,但您可以使用这样的 RAW MySQL 查询,当然首先在本地尝试:
DB::statement('alter table mytable modify mycolumn DOUBLE(15,2) DEFAULT 0');
推荐阅读
- elisp - 在elisp中隐藏一个全局变量
- python-2.7 - 使用 ChromeDriver Selenium CeleryPython 在没有 setblocking() 方法的文件对象上设置 set_nonblocking()(Windows 管道不支持非阻塞 I/O)
- javascript - Jest 无法加载 svg 文件
- docker - 如何为 Docker 检索旧图像而不是最新图像?
- javascript - React Hooks 渲染两次
- google-cloud-platform - 在 python 中使用访问令牌对 Google Storage 对象进行身份验证
- linux - 当一个数据包在linux网络堆栈中携带时,使用谁的时间片?
- python - Python如何导入本地模块?
- docker - 如何在 docker swarm 中为 Postgres 数据库容器创建持久数据卷
- android - 按钮在其顶部重叠视图