我将表迁移到了2个额外的列,其中:timestamp字段如下所示
class AddingStartAndEndTimeForQuestions < ActiveRecord::Migration
def change
add_column :questions, :eventMode, :boolean, default: false
add_column :questions, :eventModeStartTime, :timestamp
add_column :questions, :eventModeEndTime, :timestamp
end
end
我无法从rails控制台手动在此字段中插入时间戳。
我试过
q.eventModeStartTime = Time.now
q.eventModeStartTime = Time.zone.now
q.eventModeStartTime = DateTime.now
q.eventModeStartTime = Time.now.to_s(:db)
Mysql错误:
Mysql2::Error: Incorrect datetime value: '2015-09-23 22:46:28.109.109000' for column 'eventModeStartTime'
如何手动插入?我在这里做错了吗?
答案 0 :(得分:0)
INSERT INTO `db_name`.`table`
(`id`, `field`, `created_at`, `updated_at`)
VALUES
('1', 'field_value', '2020-07-05 16:42:17', '2020-07-05 16:42:18');