1
votes

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).

1
Update: I have cheated for now and added dummy dates in the old table so I can copy them across. Perhaps not the answer though... - latitudehopper

1 Answers

1
votes

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()