I have a table that needs to store epoch timestamp.
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
However, when I stored it, it becomes nil
(*the open_time
and the close_time
)
EX:
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
You can notice that the value of open_time
is gone, and the result is
#<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>
Env:
Rails 5.1.4, Ruby 2.6.5, MySQL 5.7