title: How to set a column default to a PostgreSQL function using SQLAlchemy?
body: <p>All of my tables defined in SQLAlchemy have an id column of type UUID.</p>
  <pre class="lang-py prettyprint-override"><code>from sqlalchemy.ext.declarative import declarative_base
  from uuid import uuid4
  Base = declarative_base()
  
  class MyTable(Base):
      id = Column(UUIDtype, default=uuid4, primary_key=True)
  </code></pre>
  <p>Where <code>UUIDtype</code> is a special column type for the PostgreSQL UUID type. This successfully creates the UUID column in PostgreSQL, but only generates a default UUID value when inserting using SQLAlchemy. This is fine for some of my use cases, but I want to assign the column's default on the PostgreSQL side of things in case an insert occurs outside of SQLAlchemy.</p>
  <p>The following SQL command places the proper default on the column:</p>
  <pre class="lang-sql prettyprint-override"><code>ALTER TABLE my_table ALTER COLUMN id SET DEFAULT uuid_generate_v4()
  </code></pre>
  <p>How can I assign this <code>uuid_generate_v4()</code> function as the column default through SQLAlchemy model definition? If the only option is through executing a raw SQL statement, is there a way for me to hook that statement's execution into the table creation process?</p>