Skip to content

Instantly share code, notes, and snippets.

@lly365
Created February 7, 2018 09:37
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save lly365/33252730f4ca8a6b1987a4eec7e49fa1 to your computer and use it in GitHub Desktop.
Save lly365/33252730f4ca8a6b1987a4eec7e49fa1 to your computer and use it in GitHub Desktop.
Flask-SQLAlchemy UUID
# -*- coding: utf-8 -*-
"""
pg_uuid
~~~~~~~~~~~~~~~~
<NO DESCRIPTION>.
:copyright: (c) 2018 by WRDLL <4ever@wrdll.com>
"""
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)
@georgegoldman
Copy link

thanks

@ShalithaJayamal
Copy link

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