Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix error "Cannot resolve column..."

I am developing Java web application what based on Spring Framework, MySQL, JPA. I have a problem when try to persistence data from HTML form to SQL database, then I try to debug and fix. I am using IntelliJ IDEA Ultimate 2017.1. I catch error:

Cannot resolve column 'product_name' This inspection controls whether the Persistence ORM annotations are checked against configured Datasources

This is screenshot: enter image description here

How to fix it?

like image 658
Do Nhu Vy Avatar asked May 02 '17 13:05

Do Nhu Vy


3 Answers

Open Persistence tool windows, right click on module, then set DataSource. IntelliJ IDEA will validate source code by real SQL database. enter image description here

like image 54
Do Nhu Vy Avatar answered Nov 03 '22 14:11

Do Nhu Vy


For those who just want to disable this check, go to Intellij IDEA -> Preferences -> Search "Unresolved database references in annotations" and uncheck it. enter image description here (macOS Mojave and Intellij Ultimate 2019.3)
This will disable the inspection and remove all the "Cannot resolve column…" errors on the @Column annotations. Intellij will stop checking if the String column names exist in the database tables. Do it at your own risk.

like image 18
yetsun Avatar answered Nov 03 '22 16:11

yetsun


You have to manage your data sources. I followed the steps detailed here https://www.jetbrains.com/help/pycharm/managing-data-sources.html.

In my case, I did the following (I am using Pycharms, but I assume the process is similar for other Jetbrains IDEs):

  • Bring the Data sources and drivers window by going to view > tool windows > database

  • Click the wrench icon to configure the db connection

  • Configure it, and try that the connection works with Test Connection


Pycharms should now autocomplete fields in the db.

If it still doesn't work:

  • try restarting Pycharms.
  • go to options (command + ,), then search for SQL, select menu SQL Resolution Scopes, and try adding a scope by clicking +, then selecting your current project folder as path, and your db as the resolution scope
like image 1
Benjamin Crouzier Avatar answered Nov 03 '22 14:11

Benjamin Crouzier