Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to resolve valid table in PhpStorm

Tags:

mysql

phpstorm

I'm getting unable to resolve table errors appear in php files containing SQL querying valid tables.

enter image description here

If I Ctrl + Enter over the query, then I get expected results in the DB console, and if I expand the database in the DB explorer tab then I can see the tables.

It's not affecting code execution, but it's annoying because it catches my eye when writing code, and it masks real SQL errors.

I've tried refreshing the database connection, and I've verified that the php tab is connecting to the correct database.

like image 485
Parris Varney Avatar asked Jul 12 '16 16:07

Parris Varney


4 Answers

In 2017.2 I had to go to

Settings > Languages & Frameworks > SQL Resolution Scopes

and add my project and database link in there to get it right again.

like image 102
Alex Avatar answered Nov 04 '22 01:11

Alex


Try re-creating DB connection from scratch (delete existing one and create it again).


Thinking of possible reasons ... I can think of this scenario:

  • working with project in current stable version (currently 2016.1.x);
  • trying EAP build for next version (2016.2 at this moment) on this project and make some DB-related changes there (even simple syncing DB);
  • going back to stable version (2016.1.x) .. and because new version uses newer file format/versioning for DB-related data (cached DB structure etc) IDE may start ignoring "unknown/newer" format for such data and instead of throwing appropriate warning it just "silently" throwing "unresolved table" message.

No other ideas.

like image 17
LazyOne Avatar answered Nov 04 '22 03:11

LazyOne


I was getting what OP was getting, and the problem was my DB Server was MariaDB and i had MySQL selected as the SQL Dialect.

See File > Settings: Languages & Frameworks > SQL Dialects.

like image 13
runawaycoin Avatar answered Nov 04 '22 01:11

runawaycoin


Faulty error pollution DRIVES ME NUTS TOO!

If I start having SQL resolution issues, I will check my resolution scopes (settings -> Languages & Frameworks -> SQL Resolution Scopes).

Generally I have the most issues when my project mapping is set to 'All Data Sources' by default.

The following steps always fixes it for me:

  • Click the Project Mapping Dropdown
  • Uncheck the global 'All Data Sources' setting (required to make other selection available)
  • Click the drop down arrow for your Database connection
  • Check 'All Schemas' (Or Specific Tables)
  • Click OK to close the settings window

Your false resolution errors should disappear after the next parse cycle.

You aren't limited to applying the above steps to just one DB connection, you can do it for all connections in your project.


Sometimes adding a custom resolution scope will work as well, but it is hit or miss for me.

  • Click the plus sign (top right)
  • Select the file you are working on and hit 'OK'
  • Select the 'Resolution Scope' column
  • Deselect 'all data sources'
  • Select the specific DB resources you want

Reconnecting to the DB never works for me.

Specifying the table works well... but it can become very cumbersome as the project grows.


I have also run into an additional situation where PHPStorm would only resolve some of my queries, no matter what scope resolution settings I used. However, after I attached a console to my file, they resolved just fine. (Search for 'Attach Console' in Help | Find Action. You can also add it to a 'Quick List' or Keymap it.)

like image 11
WWWebbify Avatar answered Nov 04 '22 01:11

WWWebbify