here과 같이 SQlAlchemy 권장 uuid() 지원 추가 기능을 사용하고 있습니다.SQLAlchemy 'module'을 호출 할 수 없음
TypeError: 'module' object is not callable
모듈, GUID 참조 : 내 SQLAlchemy의 코드에서 사용할 때, 나는이 오류가 발생합니다. 여기
소스에서 직접 촬영 한 GUID 코드입니다 :GUID.py 여기
from sqlalchemy.types import TypeDecorator, CHAR
from sqlalchemy.dialects.postgresql import UUID
import uuid
class GUID(TypeDecorator):
"""Platform-independent GUID type.
Uses Postgresql's UUID type, otherwise uses
CHAR(32), storing as stringified hex values.
"""
impl = CHAR
def load_dialect_impl(self, dialect):
if dialect.name == 'postgresql':
return dialect.type_descriptor(UUID())
else:
return dialect.type_descriptor(CHAR(32))
def process_bind_param(self, value, dialect):
if value is None:
return value
elif dialect.name == 'postgresql':
return str(value)
else:
if not isinstance(value, uuid.UUID):
return "%.32x" % uuid.UUID(value)
else:
# hexstring
return "%.32x" % value
def process_result_value(self, value, dialect):
if value is None:
return value
else:
return uuid.UUID(value)
그리고 것은 호출 내 모델입니다
user.py
from app import db
from datetime import datetime
from app.custom_db import GUID
class User(db.Model):
__tablename__ = 'users'
id = db.Column(GUID(), primary_key=True)
email = db.Column(db.String(80), unique=True)
name = db.Column(db.String(80))
password = db.Column(db.String(80))
datejoined = db.Column(db.DateTime,default = db.func.now())
def __init__(self, name, email, password):
self.name = name
self.email = email
self.password = password
def __repr__(self):
return '<User %r>' % self.name
이걸 만들 수없는 이유는 무엇입니까? uuid()
PKey?
여기에 전체 역 추적의
Traceback (most recent call last):
File "./run.py", line 3, in <module>
from app import app
File "/home/achumbley/Pile/app/__init__.py", line 23, in <module>
from models import user
File "/home/achumbley/Pile/app/models/user.py", line 5, in <module>
class User(db.Model):
File "/home/achumbley/Pile/app/models/user.py", line 7, in User
id = db.Column(GUID(), primary_key=True)
TypeError: 'module' object is not callable
역 추적하시기 바랍니다. –
'app/custom_db.py '는 어떻게 생겼습니까? 해당 파일에서 GUID를 가져 오므로 해당 파일이 GUID를 잘못 가져오고 있습니다. –