我有一个使用此迁移代码创建的现有表:
Schema::create('mytable', function (Blueprint $table) {
$table->increments('id');
$table->double('mycolumn',8,2)->unsigned()->default(0);
$table->timestamps();
});
Run Code Online (Sandbox Code Playgroud)
然后我创建了另一个迁移文件,mycolumn用下面的迁移文件来调整我的字段的值范围。
Schema::table('mytable', function (Blueprint $table) {
$table->double('mycolumn',15,2)->unsigned()->default(0)->change();
});
Run Code Online (Sandbox Code Playgroud)
但是我收到一个错误:
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.
Run Code Online (Sandbox Code Playgroud)
我错过了什么?
Set*_*thu 27
double不能像其他类型那样进行更改,您可以使用Doctrine \DBAL\Type修复它
您可以通过以下方式修复它:
use Doctrine\DBAL\Types\FloatType;
use Doctrine\DBAL\Types\Type;
public function up() {
if (!Type::hasType('double')) {
Type::addType('double', FloatType::class);
}
Schema::table('mytable', function($table) {
$table->double('mycolumn',15,2)->default(0)->change();
.....
});
}
Run Code Online (Sandbox Code Playgroud)
nak*_*kov 12
你在文档中遗漏了这个
只有以下列类型可以“更改”: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');
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3620 次 |
| 最近记录: |