我有一个使用此迁移代码创建的现有表:
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.
我想念什么?
答案 0 :(得分:2)
仅以下列类型可以“更改”: bigInteger,二进制,布尔值,日期,dateTime,dateTimeTz,十进制,整数,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');
答案 1 :(得分:1)
我不确定这是否会有所帮助,但在这种情况下您可以使用小数或浮点数代替双精度数,但如果您想要有限数量的小数位,则浮点数将不起作用。 所以它看起来像:
double Var1;
double Var2;
double Uitkomst;
Var1 = double.Parse(txtGetal1.Text);
Var2 = double.Parse(txtGetal2.Text);
Uitkomst = Var1 * Var2;
txtUitkomst.Text = "Uitkomst:" + Uitkomst.ToString();
答案 2 :(得分:1)
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();
.....
});
}