Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Schema Builder compileForeignKeys exception when using mysql #50512

Closed
kstych opened this issue Mar 13, 2024 · 3 comments
Closed

Schema Builder compileForeignKeys exception when using mysql #50512

kstych opened this issue Mar 13, 2024 · 3 comments

Comments

@kstych
Copy link
Contributor

kstych commented Mar 13, 2024

Laravel Version

11

PHP Version

8.2

Database Driver & Version

No response

Description

When using mysql/mariadb, the "compileForeignKeys" function requires database and table names but this function only sends table name

$this->connection->selectFromWriteConnection($this->grammar->compileForeignKeys($table))

Steps To Reproduce

dump((new \Illuminate\Database\Schema\Builder(Schema::getConnection()))->getForeignKeys('users'));
@driesvints
Copy link
Member

cc @hafezdivandari

@hafezdivandari
Copy link
Contributor

MySqlBuilder class extends Builder:

public function getForeignKeys($table)
{
$table = $this->connection->getTablePrefix().$table;
return $this->connection->getPostProcessor()->processForeignKeys(
$this->connection->selectFromWriteConnection(
$this->grammar->compileForeignKeys($this->connection->getDatabaseName(), $table)
)
);
}

Just use Schema::getForeignKeys('users') or Schema::connection('connection_name')->getForeignKeys('users') as documented here: https://laravel.com/docs/11.x/database#inspecting-your-databases

@driesvints
Copy link
Member

Thanks @hafezdivandari

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants