Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.Sign up
SQLite reflection: parentheses wrongly stripped from expression in default clause #579
I have a table (SQLite) with a column that looks like
created_at DATETIME DEFAULT (datetime('now', 'localtime')) NOT NULL,
The parentheses around
https://www.sqlite.org/lang_createtable.html (emphasis mine)
When I use
CREATE TABLE _alembic_tmp_foo ( ... created_at DATETIME DEFAULT datetime('now', 'localtime') NOT NULL, -- syntax error )
I'm new to SQLA and Alembic so please excuse me if the fault is on me.
OK SQLite doesn't give us back those parenthesis from PRAGMA table_info. It gives them back to us in the "sql" column of "sqlite_master".
however, this can be a vastly easier bug if we just say that we can apply parenthesis in all cases to column defaults. Seems to work for my arbitrary version of sqlite:
I was going to say that SQLAlchemy reflection should report on these parens but that seems a little strange.
So your workaround is pretty good, you can also use a refleciton listener like this:
I greatly prefer to fix these issues on the "render" side but in this case it's just not happening so I'll be using the above approach internally as well