Reputation: 785
I am using Postgres and Sequelize with my node app.
I have set up the models and allows Sequalize to produce the tables. I now want to move the data across using something like this.
insert into archive (id,title) select id, title from old_archives;
However, I am getting null errors as Sequelize uses createdAt and updatedAt columns. Is there a way around this?
Error is
ERROR: null value in column "createdAt" violates not-null constraint DETAIL: Failing row contains (2, null, Dewerstone Rocks, null, null, null, null, null, null, null, null).
Upvotes: 1
Views: 1011
Reputation: 28798
Instead of altering the old table you could alter the select statement to generate the required date
INSERT INTO archive (id, title, createdAt) SELECT id, title, NOW() FROM old_archives;
This selects the data from the old table, plus adds the current timestamp to each row. Of course you could also insert any other date you want instead of NOW()
Upvotes: 1