reliese / laravel

Reliese Laravel Model Generator
MIT License
1.49k stars 316 forks source link

Method Illuminate\Database\PostgresConnection::getDoctrineSchemaManager does not exist #286

Closed Daizygod closed 2 months ago

Daizygod commented 5 months ago
  1. Set up empty laravel project
  2. Config PostgreSQL database
  3. Create sample table
  4. try php artisan code:models --table=your_sample_table

Get error:

 BadMethodCallException 

  Method Illuminate\Database\PostgresConnection::getDoctrineSchemaManager does not exist.

  at vendor\laravel\framework\src\Illuminate\Macroable\Traits\Macroable.php:115
    111▕      */
    112▕     public function __call($method, $parameters)
    113▕     {
    114▕         if (! static::hasMacro($method)) {
  ➜ 115▕             throw new BadMethodCallException(sprintf(
    116▕                 'Method %s::%s does not exist.', static::class, $method
    117▕             ));
    118▕         }

  1   vendor\reliese\laravel\src\Meta\Postgres\Schema.php:286
      Illuminate\Database\Connection::__call("getDoctrineSchemaManager", [])

  2   [internal]:0
      Reliese\Meta\Postgres\Schema::schemas(Object(Illuminate\Database\PostgresConnection))

My way to fix this:

in src/Meta/Postgres/Schema.php or vendor/reliese/laravel/src/Meta/Postgres/Schema.php

in method public static function schemas(Connection $connection)

change from

public static function schemas(Connection $connection)
    {
        $schemas = $connection->getDoctrineSchemaManager()->listDatabases();

        return array_diff($schemas, [
            'postgres',
            'template0',
            'template1',
        ]);
    }

to this

public static function schemas(Connection $connection)
    {
        $schemas = array_column($connection->getSchemaBuilder()->getTables(), 'name');

        return array_diff($schemas, [
            'postgres',
            'template0',
            'template1',
        ]);
    }
ahmedK03 commented 4 months ago
  1. Set up empty laravel project
  2. Config PostgreSQL database
  3. Create sample table
  4. try php artisan code:models --table=your_sample_table

Get error:

 BadMethodCallException 

  Method Illuminate\Database\PostgresConnection::getDoctrineSchemaManager does not exist.

  at vendor\laravel\framework\src\Illuminate\Macroable\Traits\Macroable.php:115
    111▕      */
    112▕     public function __call($method, $parameters)
    113▕     {
    114▕         if (! static::hasMacro($method)) {
  ➜ 115▕             throw new BadMethodCallException(sprintf(
    116▕                 'Method %s::%s does not exist.', static::class, $method
    117▕             ));
    118▕         }

  1   vendor\reliese\laravel\src\Meta\Postgres\Schema.php:286
      Illuminate\Database\Connection::__call("getDoctrineSchemaManager", [])

  2   [internal]:0
      Reliese\Meta\Postgres\Schema::schemas(Object(Illuminate\Database\PostgresConnection))

My way to fix this:

in src/Meta/Postgres/Schema.php or vendor/reliese/laravel/src/Meta/Postgres/Schema.php

in method public static function schemas(Connection $connection)

change from

public static function schemas(Connection $connection)
    {
        $schemas = $connection->getDoctrineSchemaManager()->listDatabases();

        return array_diff($schemas, [
            'postgres',
            'template0',
            'template1',
        ]);
    }

to this

public static function schemas(Connection $connection)
    {
        $schemas = array_column($connection->getSchemaBuilder()->getTables(), 'name');

        return array_diff($schemas, [
            'postgres',
            'template0',
            'template1',
        ]);
    }

This Actually worked!! Thanks alot.

May the team build this amazing plugin update thier code, since laravel 11 removed the support for getDoctrineSchemaManager