from sqlalchemy.dialects.postgresql import UUID from flask_sqlalchemy import SQLAlchemy import uuid db = SQLAlchemy() class Foo(db.Model): id = db.Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)