点类型的默认值

问题描述 投票:2回答:2

在Laravel迁移,我应该为Point类型列的默认值使用?我本来想保持它NULL但后来我read是:

在空间索引列必须声明为NOT NULL。

所以,我应该为我的专栏的默认值使用,如何指定迁移,代表NULL,像0,0-1,-1

$table->point('location')->default(???);

UPDATE

这样做更多的研究,我发现了一个更大的问题。 MySQL不会允许POINT类型列指定默认值。所以,我必须插入NULL相当于在INSERT时间。什么是用于此目的的正确值?

mysql laravel eloquent geospatial
2个回答
0
投票

使用MariaDB的,我可以顺利插入:

- >默认(DB ::原始( “POINT(0,90)”))


0
投票

我不知道这是否是你的情况下,但如果你想一列添加到现有的表,然后添加一个空间索引到的迁移,我发现在MySQL来解决,这不是一个优雅的方式解决方案,但工作:

Schema::table('table', function(Blueprint $table)
{
    // Add the new nullable column
    $table->point('column')->nullable();
});
// You must separate this to ensure the execution order
Schema::table('table', function(Blueprint $table)
{
    // Insert the dummy values on the column
    DB::statement("UPDATE `table` SET `column` = POINT(0,90);");
    // Set the column to not null
    DB::statement("ALTER TABLE `table` CHANGE `column` `column` POINT NOT NULL;");

    // Finally add the spatial index
    $table->spatialIndex('column');
});
© www.soinside.com 2019 - 2024. All rights reserved.