-
-
Save silviud/cfc4d1b81804b77f3722dfede891d3e3 to your computer and use it in GitHub Desktop.
Flask-SQLAlchemy UUID
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
""" | |
pg_uuid | |
~~~~~~~~~~~~~~~~ | |
<NO DESCRIPTION>. | |
:copyright: (c) 2018 by WRDLL <[email protected]> | |
""" | |
from flask import Flask | |
from flask_sqlalchemy import SQLAlchemy | |
from sqlalchemy.dialects.postgresql import UUID | |
from sqlalchemy import text as sa_text | |
SECRET_KEY = 'aa' | |
SQLALCHEMY_DATABASE_URI = 'postgresql://ling:@localhost/test' | |
SQLALCHEMY_ECHO = True | |
app = Flask(__name__) | |
app.config.from_object(__name__) | |
db = SQLAlchemy(app) | |
class UuidTest(db.Model): | |
__tablename__ = 'uuid_test' | |
id = db.Column(UUID(as_uuid=True), primary_key=True, server_default=sa_text("uuid_generate_v4()")) | |
name = db.Column(db.String(10)) | |
if __name__ == '__main__': | |
app.run(debug=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment