我是拉勒维尔和波斯特格斯的新手。我使用的是没有postGres扩展的postGIS,只有postGres才允许列的点类型,即使没有postGIS,我在幼虫中的迁移失败并给出了这个错误。
照明\数据库\QueryException: SQLSTATE42704:未定义对象:7错误:在字符134处不存在“地理”类型(SQL:创建表“概要”("id“大系列主键不为空,"produc t”varchar(50) null,"details“varchar(1000) null,"xy”地理位置(点,4326)非空,"created_at“时间戳(0)没有时区空,"updated_at”时间戳(0)没有时区空)
我的迁移函数代码如下
public function up()
{
Schema::connection('pgsql')->create('profiles', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('product',50);
$table->string('details',1000);
$table->point('xy');
$table->timestamps();
});
}xy列是postgres中可用的一个简单的点类型,但看起来laravel将其转换为地理类型,这在postGIS中是可用的,在我的例子中不需要postGIS。
请建议如何在不使用postGIS的情况下在laravel中创建点列。
谢谢
发布于 2021-02-22 07:38:41
I was having same issue with Laravel Migration to create data type point for this you can use Extended version of PostgresGrammar with support of 'point' data type in Postgres <?php
namespace App\PosGress;
use Illuminate\Database\Schema\Grammars\PostgresGrammar;
use Illuminate\Support\Fluent;
/**
* Extended version of PostgresGrammar with
* support of 'point' data type in Postgres.
*/
class ExtendedPostgresGrammar extends PostgresGrammar
{
/**
* Create the column definition for a spatial Point type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typePoint(Fluent $column)
{
return "$column->type";
}
}
?>
Laravel Migration will be
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use App\PosGress\ExtendedPostgresGrammar;
class UpdateTableAddressesAddColumnPoints extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
// register new grammar class
DB::connection()->setSchemaGrammar(new ExtendedPostgresGrammar());
$schema = DB::connection()->getSchemaBuilder();
$schema->table('addresses', function (Blueprint $table) {
$table->point('geo_location')->nullable();
});
}
/**
* Reverse the migrations.
*
* @return void
*/`enter code here`
public function down()
{
Schema::table('addresses', function (Blueprint $table) {
$table->dropColumn('geo_location');
});
}
}https://stackoverflow.com/questions/58632491
复制相似问题