CREATE TABLE mytable (
...
some_timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)
otherwise you're using python-side defaults, so you'd need to write a post-table processing function:
from sqlalchemy import TIMESTAMP
def add_defaults(table):
for c in table.c:
if isinstance(c.type, TIMESTAMP):
c.default = <some default>
# ... or whatever you'd want here, c.server_default=FetchedValue(), etc
> --
> You received this message because you are subscribed to the Google Groups "sqlalchemy" group.
> To post to this group, send email to sqlal...@googlegroups.com.
> To unsubscribe from this group, send email to sqlalchemy+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
>
--
You received this message because you are subscribed to the Google Groups "sqlalchemy" group.
To view this discussion on the web visit https://groups.google.com/d/msg/sqlalchemy/-/05kepNetnrMJ.
...and, once you mark the column as having some kind of default, SQLAlchemy won't try to insert NULL into it. It's not clear here what kind of default is already on the column - though if there was one the reflection system should have gotten it.
Unless its the case that a TIMESTAMP column in SQL Server is inherently "default generating"? I haven't checked. If that's the case you'd want to set server_default=FetchedValue() on each Column. Also we'd probably want to add that to the dialect on our end at some point but it's not something I've researched.
--
You received this message because you are subscribed to the Google Groups "sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+...@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.
@event.listens_for(Table, 'column_reflect')
def receive_column_reflect(inspector, table, column_info):
if isinstance(column_info['type'], TIMESTAMP):
column_info['default'] = FetchedValue()
table = Table(table_name, metadata, autoload=True, autoload_with=engine, include_columns=columns)
File "build/bdist.linux-x86_64/egg/sqlalchemy/sql/schema.py", line 416, in __new__
File "build/bdist.linux-x86_64/egg/sqlalchemy/util/langhelpers.py", line 60, in __exit__
File "build/bdist.linux-x86_64/egg/sqlalchemy/sql/schema.py", line 411, in __new__
File "build/bdist.linux-x86_64/egg/sqlalchemy/sql/schema.py", line 484, in _init
File "build/bdist.linux-x86_64/egg/sqlalchemy/sql/schema.py", line 496, in _autoload
File "build/bdist.linux-x86_64/egg/sqlalchemy/engine/base.py", line 1972, in run_callable
File "build/bdist.linux-x86_64/egg/sqlalchemy/engine/base.py", line 1477, in run_callable
File "build/bdist.linux-x86_64/egg/sqlalchemy/engine/default.py", line 364, in reflecttable
File "build/bdist.linux-x86_64/egg/sqlalchemy/engine/reflection.py", line 568, in reflecttable
File "build/bdist.linux-x86_64/egg/sqlalchemy/engine/reflection.py", line 618, in _reflect_column
File "<string>", line 2, in text
File "build/bdist.linux-x86_64/egg/sqlalchemy/sql/elements.py", line 1425, in _create_text
File "build/bdist.linux-x86_64/egg/sqlalchemy/sql/elements.py", line 1289, in __init__
TypeError: expected string or buffer
for col in table.columns:
if isinstance(col.type, TIMESTAMP):
col.server_default = FetchedValue()