sqlalchemy_utils char(32)未找到UUIDType

时间:2017-11-13 19:51:32

标签: python postgresql sqlalchemy flask-sqlalchemy sqlalchemy-utils

我正在使用http://sqlalchemy-utils.readthedocs.io/en/latest/data_types.html#module-sqlalchemy_utils.types.uuid库的UUIDType来让我的模型使用PostgreSQL的UUID类型字段。

我按照文档上的说明进行操作,一旦安装完毕,根据文档规范将它们相应地添加到模型中:

MISC模型:

...
from sqlalchemy_utils import UUIDType, force_auto_coercion
...

force_auto_coercion()

class Misc(db.Model):
    __tablename__ = 'misc'

    id = db.Column(db.Integer, primary_key=True)
    key = db.Column(db.String(), index=True)
    user_id = db.Column(UUIDType(binary=False), db.ForeignKey('user.id'))
...

PASSPORT模型:

...
from sqlalchemy_utils import UUIDType, force_auto_coercion
...

force_auto_coercion()

class Passport(db.Model):
    __tablename__ = 'passport'

    id = db.Column(db.Integer, primary_key=True)
    public = db.Column(db.Boolean())
    status = db.Column(db.Integer, default=1)
    terms_accepted = db.Column(db.Boolean(), default=False)
    completition_level = db.Column(db.String())
    user_id = db.Column(UUIDType(binary=False), db.ForeignKey('user.id'))
...

USER模型:

...
from sqlalchemy_utils import UUIDType, force_auto_coercion
...

force_auto_coercion()

class User(db.Model):
    __tablename__ = 'user'

    id = db.Column(UUIDType(binary=False), primary_key=True)

但是当我尝试运行python manage.py migrate命令时,它会抛出以下错误(下面的完整回溯):

    Traceback (most recent call last):
  File "manage.py", line 4, in <module>
    from seed import createdata, dropdb, dropdata
  File "C:\www\liu-passport-api\seed.py", line 11, in <module>
    from flask_application import app, db
  File "C:\www\liu-passport-api\flask_application\__init__.py", line 52, in <module>
    import flask_application.controllers
  File "C:\www\liu-passport-api\flask_application\controllers\__init__.py", line 1, in <module>
    from . import information, files_manager, user
  File "C:\www\liu-passport-api\flask_application\controllers\user\__init__.py", line 1, in <module>
    from .user import UserApi
  File "C:\www\liu-passport-api\flask_application\controllers\user\user.py", line 20, in <module>
    class UserBodyApi(Resource):
  File "C:\www\liu-passport-api\flask_application\controllers\user\user.py", line 24, in UserBodyApi
    @swagger.doc(get_user_doc(User))
  File "C:\www\liu-passport-api\flask_application\controllers\user\user_doc.py", line 18, in get_user_doc
    'schema': factory(UserSchema),
  File "C:\www\liu-passport-api\env\lib\site-packages\alchemyjsonschema\__init__.py", line 318, in __call__
    schema["properties"] = self._build_properties(walker, schema, overrides=overrides, depth=depth)
  File "C:\www\liu-passport-api\env\lib\site-packages\alchemyjsonschema\__init__.py", line 379, in _build_properties
    itype, sub["type"] = self.classifier[c.type]
  File "C:\www\liu-passport-api\env\lib\site-packages\alchemyjsonschema\__init__.py", line 105, in __getitem__
    raise InvalidStatus("notfound: {k}. (cls={cls})".format(k=k, cls=cls))
alchemyjsonschema.InvalidStatus: notfound: CHAR(32). (cls=<class 'sqlalchemy_utils.types.uuid.UUIDType'>)

我做错了吗?

0 个答案:

没有答案