批量postgres插入时间戳具有null通过sequalize设置的约束

我用我的节点应用程序使用Postgres和Sequelize。

我已经build立了模型,并允许Sequalize生成表格。 我现在想要使用这样的东西来移动数据。 insert into archive (id,title) select id, title from old_archives; 但是,由于Sequelize使用createdAt和updatedAt列,我得到空错误。 有没有解决的办法?

错误是

错误:“createdAt”列中的空值违反了非空约束。细节:失败的行包含(2,null,Dewerstone Rocks,null,null,null,null,null,null,null)。

而不是改变旧表,你可以改变select语句来生成所需的date

 INSERT INTO archive (id, title, createdAt) SELECT id, title, NOW() FROM old_archives; 

这将从旧表中select数据,并将当前时间戳添加到每一行。 当然,你也可以插入任何其他的date而不是NOW()