1

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

latitudehopper
  • 735
  • 2
  • 7
  • 23
  • 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 Jan 05 '16 at 14:57

1 Answers1

1

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

Jan Aagaard Meier
  • 28,078
  • 8
  • 95
  • 66