Search code examples
phpphpstorm

PhpStorm - associate SQL schema with project source


PhpStorm reports Unresolved reference errors for SQL statements in source code editor:

Unable to resolve column expiry_time

Inspection info: This inspection performs unresolved SQL references check

There is a MySQL schema file for the project, but I can't find how to associate this schema file with the project source.

Clicking on the red lightbulb on the left hand side enables creating a new table but can't see how to import an existing table definition.


Solution

  • You need to create a new Data Source in Database toolwindow and point to your database (be it dev version or maybe even a live one).

    If using an actual database is not possible for whatever reason (specific environment requirements/restrictions or whatnot) but you have schema file, sill create a Data Source but point to your DDL/schema file instead.

    See this page for exact steps: https://www.jetbrains.com/help/phpstorm/connecting-to-a-database.html#create_ddl_data_source