[英]SQLAlchemy/Python 3 (default column value)
I have an SQLAlchemy model that (simplified) looks like this: 我有一个SQLAlchemy模型(简化)看起来像这样:
class User(db.Model):
created = db.Column(db.DateTime(), nullable=False, default=datetime.datetime.utcnow, onupdate=datetime.datetime.utcnow)
This worked fine with Python 2.7, but now that I've upgraded to Python 3.4.0 I get this error when trying to insert something into the database: 这在Python 2.7中运行良好,但是现在我已经升级到Python 3.4.0了,当我尝试在数据库中插入一些东西时会出现这个错误:
sqlalchemy.exc.StatementError: utcnow() takes no arguments (1 given) (original cause: TypeError: utcnow() takes no arguments (1 given))
Any ideas? 有任何想法吗? Thanks in advance. 提前致谢。
default
and onupdate
functions can take an optional context
argument. default
和onupdate
函数可以使用可选的context
参数。 See here . 看到这里 。 I'm not sure how sqlalchemy detects whether to pass this, but maybe something in 3.4 is messing with the detection. 我不确定sqlalchemy是如何检测是否通过这个,但3.4中的某些内容可能会使检测变得混乱。 You might want to report a bug . 您可能想要报告错误 。
SQLAlchemy有一个已知的问题,可以在0.9.4发行说明的这一节中看到
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.