Managing Data Sources
About data sources
To be able to work with your databases in PyCharm, you should define them as data sources. See Connecting to a database.
In addition to data sources that correspond to real databases (DB data sources), PyCharm also supports DDL data sources. These are represented by one or more SQL files containing data definition language statements (SQL DDL statements).
Metaphorically, DDL data sources function as databases without data.
Data sources provide the basis for SQL coding assistance and code validation.
Creating DB data sources by importing connection settings
Files that contain database connection settings (e.g.
settings.py) can be used for creating DB data sources.
- If the files that you want to import the settings from are not in your project yet, copy them there.
- Open the Database tool window.
- Do one of the following:
- Click on the toolbar and select Import from sources.
- Right-click the area under the toolbar or any of the existing data sources, point to New and click Import from sources.
- Specify the driver files if they are missing.
Do one of the following:
- To download the necessary driver, click the Download link.
- To specify the driver files that you already have available on your computer, click the <DriverName> link to the right of Driver.
Go back to the page with the data source settings.
- Click Test Connection to make sure that PyCharm can properly communicate with the database.
- Click OK in the Data Sources and Drivers dialog.
Creating a DDL data source
- Open the Database tool window and click on the toolbar.
- In the Data Sources and Drivers dialog that opens, click and select DDL Data Source.
- In the Name field, if necessary, edit the name of the data source.
- Under DDL Files, click and select the necessary SQL file or files in the dialog that opens.
- From the Extend list, if necessary, select another data source as a parent. As a result, the data source whose properties you are editing will "inherit" all the DDL definitions from its parent.
- Click OK to save the settings and close the dialog.
Changing data source settings
- Open the Database tool window and select the data source of interest.
- Do one of the following:
- In the Data Sources and Drivers dialog that opens, edit the settings as necessary. See:
Making a DB data source available in all your projects
When a DB data source is created, it's assigned to a project. That is, by default, it's available only in the project in which it was defined.
If you want to make a data source available in all your projects, you should make it global:
- Open the Data Sources and Drivers dialog (e.g. Alt+Enter ) and select the data source of interest.
- Click on the toolbar or select Make Global from the context menu.
- Click Apply or OK.
Note that the DDL data sources exist only on the project level.