【发布时间】:2020-08-29 02:27:09
【问题描述】:
我有一个需要存储纪元时间戳的表。
class CreateKlines < ActiveRecord::Migration[5.1]
def change
create_table :klines do |t|
t.string :symbol
t.timestamp :open_time
t.timestamp :close_time
t.timestamps
end
end
但是,当我存储它时,它变成了nil
(*open_time 和 close_time)
前:
Kline.create(open_time: Time.now.to_i)
(0.3ms) BEGIN
SQL (1.5ms) INSERT INTO `klines` (`created_at`, `updated_at`) VALUES ('2020-05-14 01:45:22', '2020-05-14 01:45:22')
(3.8ms) COMMIT
你可以注意到open_time的值没有了,结果是
#<Kline:0x00007f9f68c87788
id: 600,
symbol: nil,
open_time: nil,
close_time: nil,
created_at: Thu, 14 May 2020 01:45:22 UTC +00:00,
updated_at: Thu, 14 May 2020 01:45:22 UTC +00:00>
环境:
导轨 5.1.4, 红宝石 2.6.5, MySQL 5.7
【问题讨论】:
标签: ruby-on-rails ruby timestamp epoch