Skip to content

Commit a4e5f11

Browse files
authored
Fixed bug that gen:model cannot work when using pgsql. (#7400)
1 parent efae6d4 commit a4e5f11

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/Commands/ModelCommand.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,12 @@ protected function createModel(string $table, ModelOption $option): void
158158
$table = Str::replaceFirst($option->getPrefix(), '', $table);
159159
$pureTable = Str::after($table, '.');
160160
$databaseName = Str::contains($table, '.') ? Str::before($table, '.') : null;
161-
$columns = $this->formatColumns($builder->getColumnTypeListing($pureTable, $databaseName));
161+
$driver = $this->resolver->connection($option->getPool())->getConfig('driver');
162+
$columns = match ($driver) {
163+
'pgsql' => $this->formatColumns($builder->getColumnTypeListing($table, $databaseName)),
164+
default => $this->formatColumns($builder->getColumnTypeListing($pureTable, $databaseName)),
165+
};
166+
162167
if (empty($columns)) {
163168
$this->output?->error(
164169
sprintf('Query columns are empty, maybe the table `%s` does not exist. You can check it in the database.', $table)

src/Schema/Blueprint.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1492,6 +1492,11 @@ protected function addImpliedCommands(Grammar $grammar)
14921492
$this->addFluentIndexes();
14931493

14941494
$this->addFluentCommands($grammar);
1495+
1496+
// Add table comment command for PostgreSQL if table has comment and is being created
1497+
if ($this->creating() && ! empty($this->comment) && in_array('TableComment', $grammar->getFluentCommands())) {
1498+
$this->addCommand('tableComment', ['value' => $this->comment]);
1499+
}
14951500
}
14961501

14971502
/**

0 commit comments

Comments
 (0)