-
Notifications
You must be signed in to change notification settings - Fork 14.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Running airflow db init
raises OperationalError on SQL: ALTER TABLE xcom DROP COLUMN id
#18457
Comments
Thanks for opening your first issue here! Be sure to follow the issue template! |
As the error says "Unable to create or change a table without a primary key, when the system variable 'sql_require_primary_key' is set". This setting was apparently introduced in MySQL 8.0.13 and is OFF by default, so I guess you have enabled it. The XCom table does include a primary key (dag_id, task_id, key, execution_date), but the migration script first removes the (old) id column, which fails in combination with sql_require_primary_key=ON. Is it possible to disable it temporarily, and enable afterwards? On the Airflow side, would you be willing to add a check for this setting and/or add this information to the docs? |
It works, thanks! But here's the thing, I was using a managed database from DigitalOcean where the only way to change the config If I change it on my own like so: SET sql_require_primary_key=OFF It will reset back to ON for new connections - so there is no way to set the variable to OFF when running So what I ended up doing is:
SET sql_require_primary_key=OFF;
ALTER TABLE xcom DROP COLUMN id;
It works but it feels hacky to me Maybe on the Airflow side, we can check if the setting is ON, and then if it is ON just set it to OFF right before we run |
Yeah. Good one @BasPH -> I am all for "no user/support involvement" if needed. We already do a couple of things automatically to deal with MySQL and MsSQL "configurability":
In this case I think just enabling/disabling it for this migration only would be best solution (and we can actually test it very easily - we could set that option in https://github.com/apache/airflow/blob/main/scripts/ci/mysql/conf.d/airflow.cnf (providing that it is settable there) and our MySQL tests would create a db with |
Turns out SET SESSION sql_mode = 'TRADITIONAL';
SET LOCAL sql_mode = 'TRADITIONAL';
SET @@SESSION.sql_mode = 'TRADITIONAL';
SET @@LOCAL.sql_mode = 'TRADITIONAL';
SET @@sql_mode = 'TRADITIONAL';
SET sql_mode = 'TRADITIONAL';
@potiuk I'll go ahead and give it try |
Just a hint. One good thing to try is to change the setting in MySQL config and see it fail the migration before fixing :). Just to be sure that the setting is effective. You can very easily test it locally. Just |
Is there an issue here to address? it looks more like a question/answer thread :) |
Ah sorry, completely forgot about it @eladkal the issue is that the migration doesn't work when the config I think this is still a issue, I'll check again and try to make a PR in the next few days if it still is |
@leonarduschen - that would be great if you can come back to it. And the solution with temporary switching off the require_primary_key (when in MYSQL) is actually the only one I can see works (and it is not really hacky - the settings is not "database" setting really. This is runtime in-session check that MySQL adds and it's perfectly OK to disable it if you know what you are doing. Other than recreating tables with SELECT FROM AS, there is not much you can do. in this case. |
This issue has been automatically marked as stale because it has been open for 30 days with no response from the author. It will be closed in next 7 days if no further activity occurs from the issue author. |
This issue has been closed because it has not received response from the issue author. |
Apache Airflow version
2.1.3
Operating System
Pop!_OS 21.04 x86_64
Versions of Apache Airflow Providers
apache-airflow-providers-ftp==2.0.1
apache-airflow-providers-http==2.0.1
apache-airflow-providers-imap==2.0.1
apache-airflow-providers-sqlite==2.0.1
Deployment
Other
Deployment details
Using
venv
on Python 3.9.5What happened
Running
airflow db init
givesWhat you expected to happen
Initialization succeeds
How to reproduce
Use MySQL version 8
Set env variables
Create database
Setup my.cnf
Run
airflow db init
Anything else
Every time
Are you willing to submit PR?
Code of Conduct
The text was updated successfully, but these errors were encountered: