From c3b97fdd239b516cbc0308762a130f103e7c2f1a Mon Sep 17 00:00:00 2001 From: Anon Ray Date: Sun, 11 May 2014 17:12:50 +0530 Subject: [PATCH] Fix db create error in MySQL - MySQL needs fixed lengths in VARCHAR datatypes. Fixing code to have that for MySQL. --- dbsetup.py | 8 ++++---- swtstore/classes/models/sweet.py | 2 +- swtstore/classes/models/types.py | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/dbsetup.py b/dbsetup.py index 3d9b535..9fdc821 100644 --- a/dbsetup.py +++ b/dbsetup.py @@ -20,10 +20,10 @@ db = getDBInstance() # Import all modules which represents a SQLAlchemy model; # they have corresponding tables that are needed to be created -from swtstore.classes.models import Sweet, Context, Client, AuthorizedClients +from swtstore.classes.models import Sweet, Context, Client from swtstore.classes.models.um import User, Group, Membership -# Create them! -db.create_all() - +if __name__ == '__main__': + # Create them! + db.create_all() diff --git a/swtstore/classes/models/sweet.py b/swtstore/classes/models/sweet.py index 29677e1..58b251b 100644 --- a/swtstore/classes/models/sweet.py +++ b/swtstore/classes/models/sweet.py @@ -25,7 +25,7 @@ class Sweet(db.Model): context_id = db.Column(db.Integer, db.ForeignKey('contexts.id')) what = db.relationship('Context') - where = db.Column(db.String, nullable=False) + where = db.Column(db.UnicodeText, nullable=False) how = db.Column(JSONType) diff --git a/swtstore/classes/models/types.py b/swtstore/classes/models/types.py index 8ad87c0..34290bb 100644 --- a/swtstore/classes/models/types.py +++ b/swtstore/classes/models/types.py @@ -15,7 +15,7 @@ class JSONType(types.TypeDecorator): similarly, convert string to dict while loading from database """ - impl = types.Unicode + impl = types.UnicodeText def process_bind_param(self, value, dialect): return json.dumps(value) -- 1.7.10.4