点类型的默认值

uxh89sit  于 2021-06-18  发布在  Mysql
关注(0)|答案(2)|浏览(462)

在laravel迁移中,我应该使用什么作为 Point 类型列?我本来想留着的 NULL 但后来我读到:
空间索引中的列必须声明为非空。
那么,我应该使用什么作为我的列的默认值,以及如何在迁移中指定它来表示 NULL ,大概是 0,0 或者 -1,-1 ?

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

更新
做了更多的研究,我发现了一个更大的问题。mysql不允许为 POINT 键入列。所以我必须插入一个 NULL -等效于 INSERT 时间。为此,正确的值是多少?

yzuktlbb

yzuktlbb1#

我不知道这是不是你的情况,但如果你试图向现有表中添加一列,然后在迁移时向表中添加空间索引,我发现在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');
});
72qzrwbm

72qzrwbm2#

使用mariadb,我可以通过以下方式成功插入:
->默认值(db::raw(“点(0,90)”))

相关问题