Getting error [Doctrine\DBAL\DBALException] Unknown database type point requested, Doctrine\DBAL\Platforms\MySQL57Platform may not support it
Asked Answered
B

3

5

I'm using Laravel and I just added a new migration for increasing column size. The first generated table has a column named latlong of type Point. I can't modify any column size?

When I try to modify a column's size, I get the error below:

[Doctrine\DBAL\DBALException]
Unknown database type point requested, Doctrine\DBAL\Platforms\MySQL57Platform may not support it.

Here are my migration files. First migration is for create a table abc

public function up()
{
 Schema::create('abc', function (Blueprint $table) {
        $table->increments('id');
        $table->string('first_name', 20);
        $table->string('last_name', 20);
        $table->string('street', 100);
        $table->string('city', 50)->nullable();
        $table->string('state', 50)->nullable();
        $table->string('postal_code', 15);
        $table->string('mobile', 10)->nullable();
        $table->timestamps();
        $table->softDeletes();
});   
Illuminate\Support\Facades\DB::statement('ALTER TABLE abc ADD latlong POINT');

}

Second migration is for update column size

public function up()
{
 Schema::table('abc', function (Blueprint $table){
     $table->string('mobile', 20)->nullable()->change();
 });
}

Can anyone please help me with this?

Bookcraft answered 25/11, 2017 at 9:57 Comment(3)
May be Point is not supported by laravel check this answer to fix this issueGrubbs
yes, Point is the issue here.Bookcraft
if I use Illuminate\Support\Facades\DB::statement('ALTER TABLE abc MODIFY mobile VARCHAR(20)'); then it's working fine for me. But I don't want to use this solution.Bookcraft
H
9

In your migration, add the following function:

public function __construct()
{
    \Illuminate\Support\Facades\DB::getDoctrineSchemaManager()
       ->getDatabasePlatform()->registerDoctrineTypeMapping('point', 'string');
}
Hinckley answered 13/6, 2019 at 6:19 Comment(1)
I'd suggest the Doctrine type should be "binary" not "string" for this. And note that this needs to be added to any migration that alters a table with a POINT column.Nephritic
Z
0

If you suddenly get this problem on Symfony, try to delete the var folder to reset the cache, and execute the command one more time to see if it works.

Z answered 26/12, 2023 at 4:34 Comment(0)
G
0

I just used the accepted answer from @Ali Khalili and @miken32 for a model with a point field, which worked a treat. However, I got a deprecation warning for getDoctrineSchemaManager()->getDatabasePlatform().

Changed to getDoctrineConnection()->getDatabasePlatform(), this is using doctrine/dbal 3.9.x

Gittel answered 17/10 at 15:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.