Created
February 7, 2018 09:37
-
-
Save lly365/33252730f4ca8a6b1987a4eec7e49fa1 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) |
How to add these data into database using python terminal.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thanks