@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,
On 12/11/2015 01:12 PM, mdob wrote:
> |
>
> @event.listens_for(Table,'column_reflect')
> defreceive_column_reflect(inspector,table,column_info):
> ifisinstance(column_info['type'],TIMESTAMP):
> column_info['default']=FetchedValue()
>
the reflection wants to assume the
Maybe this should go into server_default. Because cole belowe worked fine.
for col in table.columns:
if isinstance(col.type, TIMESTAMP):
col.server_default = FetchedValue()
Updating column_info['server_default'] = FetchedValue() in event handler
didn't work.
On Friday, December
probably (maybe we should improve on our end, though). but when you’re
autoloading, you can set this default up automatically using the column_reflect
event:
http://docs.sqlalchemy.org/en/rel_0_9/core/events.html?highlight=column_reflect#sqlalchemy.events.DDLEvents.column_reflect
Thanks so much Michael.. just to wrap up this thread, I got it working like
this:
class Thing(Base):
__tablename__ = 'tbThings'
__table_args__ = (
{'autoload':True,'autoload_with':engine,'extend_existing':True}
)
LastUpdated = Column('LastUpdated', TIMESTAMP,
Hi,
I am autoloading tables from an MSSQL db. A lot of the tables have
the MSSQL TIMESTAMP column. So, when inserting to the table, I get an
IntegrityError:
sqlalchemy.exc.IntegrityError: (IntegrityError) ('23000', '[23000]
[FreeTDS][SQL Server]Cannot insert an explicit value into a timestamp
Ideally this TIMESTAMP column would have a default declared at the server level:
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
Hi Michael,
Thanks for your reply. Please be patient with me though as I don't quite
get it.
Where and when is the add_default function called? Won't I get the same
error trying to insert 'some default' into the column?
Any further explanation would be great.
Matt
--
You received this
you'd call it as soon as you reflect your table.
my_table = Table('some_table', metadata, autoload=True)
add_default(my_table)
probably worthwhile to make a function:
def reflect_table(name, metadata):
my_table = Table('some_table', metadata, autoload=True)
add_default(my_table)
On Sep 15, 2011, at 10:51 AM, Matt Bodman wrote:
Hi Michael,
Thanks for your reply. Please be patient with me though as I don't quite get
it.
Where and when is the add_default function called? Won't I get the same
error trying to insert 'some default' into the column?
Any
10 matches
Mail list logo