我正在使用UUIDType
http://sqlalchemy-utils.readthedocs.io/en/latest/data_types.html#module-sqlalchemy_utils.types.uuid库使我的模型使用 PostgreSQL 的 UUID 类型字段。
我按照文档上的说明进行操作,一旦安装,它们就会根据文档的规范相应地添加到模型中:
杂项型号:
...
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'))
...
护照型号:
...
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'))
...
用户型号:
...
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'>)
难道我做错了什么?