I am trying to use MysqlOperator and PostgresOperator of Airflow
from airflow.operators.postgres_operator import PostgresOperator
from airflow.providers.mysql.operators.mysql import MySqlOperator
Even though I installed all the required files, I still get the same error:
ModuleNotFoundError: No module named 'airflow.providers.postgres.operators'
I am trying to use MysqlOperator and PostgresOperator of Airflow
from airflow.operators.postgres_operator import PostgresOperator
from airflow.providers.mysql.operators.mysql import MySqlOperator
Even though I installed all the required files, I still get the same error:
Share Improve this question asked Mar 21 at 22:53 AleynaAleyna 12 bronze badgesModuleNotFoundError: No module named 'airflow.providers.postgres.operators'
1 Answer
Reset to default 1The individual Operators for databases have been replaced with the Sql Commons operators. Specifically, if you are running those two, you will want to use the SQLExecuteQueryOperator. If you look at the operator, it pulls the appropriate hook based on the connection type specified in the conn_id
.
If you would still like to use the PostgresOperator, you can call it in Postgres providers versions up to 5.14.0 and 5.7.4 for the MySqlOperator, but you'll notice looking at the actual code itself that it will essentially redirect you to the SqlExecuteQueryOperator and provide a deprecation warning.
You still need to install the Providers packages to get the proper hook for the connection, but for your dag code itself, you only need one import.
from airflow.providersmon.sql.operators.sql import SQLExecuteQueryOperator