是否可以只将时间存储在烧瓶sqlalchemy中。 因为只有我们可以使用的日期时间,我只想存储时间。
答案 0 :(得分:1)
是的,这是可能的。我假设您要使用MySQL TIME类型:http://dev.mysql.com/doc/refman/5.6/en/time.html:
root@localhost [test]> show create table Foo\G
*************************** 1. row ***************************
Table: Foo
Create Table: CREATE TABLE `Foo` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`time` time NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
1 row in set (0.00 sec)
root@localhost [inDB]> insert into Foo(time) values (CURRENT_TIMESTAMP);
Query OK, 1 row affected (0.00 sec)
root@localhost [inDB]> select * from Foo;
+----+----------+
| id | time |
+----+----------+
| 1 | 20:35:36 |
+----+----------+
1 row in set (0.00 sec)
要通过sqla创建它,您必须包含特定于mysql的方言:
from sqlalchemy.dialects.mysql TIME
Base = declarative_base()
class Foo(Base):
__tablename__ = 'Foo'
id = Column(Integer, nullable=False, primary_key=True, autoincrement=True)
time = Column(TIME(), nullable=False)