Is it possible to store only time in flask sqlalchemy. Because there is only datetime available to us and I want to store only time.
Yes, it's possible. I assume you want to use MySQL TIME type: 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)
To create it via sqla, you have to include mysql-specific dialect:
from sqlalchemy.dialects.mysql import TIME
Base = declarative_base()
class Foo(Base):
__tablename__ = 'Foo'
id = Column(Integer, nullable=False, primary_key=True, autoincrement=True)
time = Column(TIME(), nullable=False)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With