Winston Huang created AIRFLOW-2026:
--------------------------------------
Summary: airflow initdb fails on add_time_zone_awareness migration
Key: AIRFLOW-2026
URL: https://issues.apache.org/jira/browse/AIRFLOW-2026
Project: Apache Airflow
Issue Type: Bug
Affects Versions: 1.10.0
Reporter: Winston Huang
{{airflow initdb}} currently fails on a fresh MySQL database
Run off master at 18d09a9481800baf8c546814564aafcfa8ed0e1b:
{noformat}
AIRFLOW_HOME=. airflow initdb
[2018-01-23 14:22:54,668] {__init__.py:45} INFO - Using executor
SequentialExecutor
DB: mysql://airflow@localhost/airflow_test
[2018-01-23 14:22:54,876] {db.py:300} INFO - Creating tables
INFO [alembic.runtime.migration] Context impl MySQLImpl.
INFO [alembic.runtime.migration] Will assume non-transactional DDL.
INFO [alembic.runtime.migration] Running upgrade -> e3a246e0dc1, current schema
INFO [alembic.runtime.migration] Running upgrade e3a246e0dc1 -> 1507a7289a2f,
create is_encrypted
INFO [alembic.runtime.migration] Running upgrade 1507a7289a2f -> 13eb55f81627,
maintain history for compatibility with earlier migrations
INFO [alembic.runtime.migration] Running upgrade 13eb55f81627 -> 338e90f54d61,
More logging into task_isntance
INFO [alembic.runtime.migration] Running upgrade 338e90f54d61 -> 52d714495f0,
job_id indices
INFO [alembic.runtime.migration] Running upgrade 52d714495f0 -> 502898887f84,
Adding extra to Log
INFO [alembic.runtime.migration] Running upgrade 502898887f84 -> 1b38cef5b76e,
add dagrun
INFO [alembic.runtime.migration] Running upgrade 1b38cef5b76e -> 2e541a1dcfed,
task_duration
INFO [alembic.runtime.migration] Running upgrade 2e541a1dcfed -> 40e67319e3a9,
dagrun_config
INFO [alembic.runtime.migration] Running upgrade 40e67319e3a9 -> 561833c1c74b,
add password column to user
INFO [alembic.runtime.migration] Running upgrade 561833c1c74b -> 4446e08588,
dagrun start end
INFO [alembic.runtime.migration] Running upgrade 4446e08588 -> bbc73705a13e,
Add notification_sent column to sla_miss
INFO [alembic.runtime.migration] Running upgrade bbc73705a13e -> bba5a7cfc896,
Add a column to track the encryption state of the 'Extra' field in connection
INFO [alembic.runtime.migration] Running upgrade bba5a7cfc896 -> 1968acfc09e3,
add is_encrypted column to variable table
INFO [alembic.runtime.migration] Running upgrade 1968acfc09e3 -> 2e82aab8ef20,
rename user table
INFO [alembic.runtime.migration] Running upgrade 2e82aab8ef20 -> 211e584da130,
add TI state index
INFO [alembic.runtime.migration] Running upgrade 211e584da130 -> 64de9cddf6c9,
add task fails journal table
INFO [alembic.runtime.migration] Running upgrade 64de9cddf6c9 -> f2ca10b85618,
add dag_stats table
INFO [alembic.runtime.migration] Running upgrade f2ca10b85618 -> 4addfa1236f1,
Add fractional seconds to mysql tables
INFO [alembic.runtime.migration] Running upgrade 4addfa1236f1 -> 8504051e801b,
xcom dag task indices
INFO [alembic.runtime.migration] Running upgrade 8504051e801b -> 5e7d17757c7a,
add pid field to TaskInstance
INFO [alembic.runtime.migration] Running upgrade 5e7d17757c7a -> 127d2bf2dfa7,
Add dag_id/state index on dag_run table
INFO [alembic.runtime.migration] Running upgrade 127d2bf2dfa7 -> cc1e65623dc7,
add max tries column to task instance
INFO [alembic.runtime.migration] Running upgrade cc1e65623dc7 -> bdaa763e6c56,
Make xcom value column a large binary
INFO [alembic.runtime.migration] Running upgrade bdaa763e6c56 -> 947454bf1dff,
add ti job_id index
INFO [alembic.runtime.migration] Running upgrade 947454bf1dff -> d2ae31099d61,
Increase text size for MySQL (not relevant for other DBs' text types)
INFO [alembic.runtime.migration] Running upgrade d2ae31099d61 -> 0e2a74e0fc9f,
Add time zone awareness
Traceback (most recent call last):
File "/Users/winstonhuang/.virtualenvs/airflow_test/bin/airflow", line 27, in
<module>
args.func(args)
File
"/Users/winstonhuang/.virtualenvs/airflow_test/lib/python2.7/site-packages/airflow/bin/cli.py",
line 890, in initdb
db_utils.initdb()
File
"/Users/winstonhuang/.virtualenvs/airflow_test/lib/python2.7/site-packages/airflow/utils/db.py",
line 87, in initdb
upgradedb()
File
"/Users/winstonhuang/.virtualenvs/airflow_test/lib/python2.7/site-packages/airflow/utils/db.py",
line 308, in upgradedb
command.upgrade(config, 'heads')
File
"/Users/winstonhuang/.virtualenvs/airflow_test/lib/python2.7/site-packages/alembic/command.py",
line 174, in upgrade
script.run_env()
File
"/Users/winstonhuang/.virtualenvs/airflow_test/lib/python2.7/site-packages/alembic/script/base.py",
line 416, in run_env
util.load_python_file(self.dir, 'env.py')
File
"/Users/winstonhuang/.virtualenvs/airflow_test/lib/python2.7/site-packages/alembic/util/pyfiles.py",
line 93, in load_python_file
module = load_module_py(module_id, path)
File
"/Users/winstonhuang/.virtualenvs/airflow_test/lib/python2.7/site-packages/alembic/util/compat.py",
line 79, in load_module_py
mod = imp.load_source(module_id, path, fp)
File
"/Users/winstonhuang/.virtualenvs/airflow_test/lib/python2.7/site-packages/airflow/migrations/env.py",
line 86, in <module>
run_migrations_online()
File
"/Users/winstonhuang/.virtualenvs/airflow_test/lib/python2.7/site-packages/airflow/migrations/env.py",
line 81, in run_migrations_online
context.run_migrations()
File "<string>", line 8, in run_migrations
File
"/Users/winstonhuang/.virtualenvs/airflow_test/lib/python2.7/site-packages/alembic/runtime/environment.py",
line 807, in run_migrations
self.get_context().run_migrations(**kw)
File
"/Users/winstonhuang/.virtualenvs/airflow_test/lib/python2.7/site-packages/alembic/runtime/migration.py",
line 321, in run_migrations
step.migration_fn(**kw)
File
"/Users/winstonhuang/.virtualenvs/airflow_test/lib/python2.7/site-packages/airflow/migrations/versions/0e2a74e0fc9f_add_time_zone_awareness.py",
line 61, in upgrade
op.alter_column(table_name='sla_miss', column_name='execution_date',
type_=mysql.TIMESTAMP(fsp=6))
File "<string>", line 8, in alter_column
File "<string>", line 3, in alter_column
File
"/Users/winstonhuang/.virtualenvs/airflow_test/lib/python2.7/site-packages/alembic/operations/ops.py",
line 1420, in alter_column
return operations.invoke(alt)
File
"/Users/winstonhuang/.virtualenvs/airflow_test/lib/python2.7/site-packages/alembic/operations/base.py",
line 318, in invoke
return fn(self, operation)
File
"/Users/winstonhuang/.virtualenvs/airflow_test/lib/python2.7/site-packages/alembic/operations/toimpl.py",
line 53, in alter_column
**operation.kw
File
"/Users/winstonhuang/.virtualenvs/airflow_test/lib/python2.7/site-packages/alembic/ddl/mysql.py",
line 67, in alter_column
else existing_autoincrement
File
"/Users/winstonhuang/.virtualenvs/airflow_test/lib/python2.7/site-packages/alembic/ddl/impl.py",
line 118, in _exec
return conn.execute(construct, *multiparams, **params)
File
"/Users/winstonhuang/.virtualenvs/airflow_test/lib/python2.7/site-packages/sqlalchemy/engine/base.py",
line 945, in execute
return meth(self, multiparams, params)
File
"/Users/winstonhuang/.virtualenvs/airflow_test/lib/python2.7/site-packages/sqlalchemy/sql/ddl.py",
line 68, in _execute_on_connection
return connection._execute_ddl(self, multiparams, params)
File
"/Users/winstonhuang/.virtualenvs/airflow_test/lib/python2.7/site-packages/sqlalchemy/engine/base.py",
line 1002, in _execute_ddl
compiled
File
"/Users/winstonhuang/.virtualenvs/airflow_test/lib/python2.7/site-packages/sqlalchemy/engine/base.py",
line 1189, in _execute_context
context)
File
"/Users/winstonhuang/.virtualenvs/airflow_test/lib/python2.7/site-packages/sqlalchemy/engine/base.py",
line 1402, in _handle_dbapi_exception
exc_info
File
"/Users/winstonhuang/.virtualenvs/airflow_test/lib/python2.7/site-packages/sqlalchemy/util/compat.py",
line 203, in raise_from_cause
reraise(type(exception), exception, tb=exc_tb, cause=cause)
File
"/Users/winstonhuang/.virtualenvs/airflow_test/lib/python2.7/site-packages/sqlalchemy/engine/base.py",
line 1182, in _execute_context
context)
File
"/Users/winstonhuang/.virtualenvs/airflow_test/lib/python2.7/site-packages/sqlalchemy/engine/default.py",
line 470, in do_execute
cursor.execute(statement, parameters)
File
"/Users/winstonhuang/.virtualenvs/airflow_test/lib/python2.7/site-packages/MySQLdb/cursors.py",
line 250, in execute
self.errorhandler(self, exc, value)
File
"/Users/winstonhuang/.virtualenvs/airflow_test/lib/python2.7/site-packages/MySQLdb/connections.py",
line 50, in defaulterrorhandler
raise errorvalue
sqlalchemy.exc.DataError: (_mysql_exceptions.DataError) (1171, 'All parts of a
PRIMARY KEY must be NOT NULL; if you need NULL in a key, use UNIQUE instead')
[SQL: u'ALTER TABLE sla_miss MODIFY execution_date TIMESTAMP(6) NULL']{noformat}
It looks like {{sla_miss}} has a composite primary key that includes
{{execution_date}}, and that this alter statement
([https://github.com/apache/incubator-airflow/blob/master/airflow/migrations/versions/0e2a74e0fc9f_add_time_zone_awareness.py#L61)]
defaults {{nullable}} to {{True}}. So I think it's necessary to specify the
{{nullable}} parameter as {{False}} in the migration. Let me know if I'm
missing something - thanks!
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)