点类型的默认值

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

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

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

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

yzuktlbb

yzuktlbb1#

我不知道这是不是你的情况,但如果你试图向现有表中添加一列,然后在迁移时向表中添加空间索引,我发现在mysql中解决这个问题的方法不是一个优雅的解决方案,而是行之有效的:

  1. Schema::table('table', function(Blueprint $table)
  2. {
  3. // Add the new nullable column
  4. $table->point('column')->nullable();
  5. });
  6. // You must separate this to ensure the execution order
  7. Schema::table('table', function(Blueprint $table)
  8. {
  9. // Insert the dummy values on the column
  10. DB::statement("UPDATE `table` SET `column` = POINT(0,90);");
  11. // Set the column to not null
  12. DB::statement("ALTER TABLE `table` CHANGE `column` `column` POINT NOT NULL;");
  13. // Finally add the spatial index
  14. $table->spatialIndex('column');
  15. });
展开查看全部
72qzrwbm

72qzrwbm2#

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

相关问题