3

Hey I m trying to insert data into my product row

INSERT INTO products (title, category, quantity, price, createdAt) VALUES ('my     
bag', 'hipster', 2, 99.99, NOW());

However, I am getting this error: ERROR: column "createdat" of relation "products" does not exist

Any ideas? Thanks!!

javascript2016
  • 973
  • 3
  • 17
  • 41
  • 5
    You created the column as `"createdAt"` so you must quote it forevermore. Quoted identifiers are case sensitive, the recommended practice with PostgreSQL is to use names like `created_at` instead. – mu is too short Sep 08 '16 at 19:47
  • Thanks! The error is gone now, but nothing is being added to my database.. – javascript2016 Sep 08 '16 at 19:55
  • Then you have a completely different problem and it is time to do a bit of debugging, there's no way anyone can tell you what's wrong with the limited information here. – mu is too short Sep 08 '16 at 21:20
  • actually now I tried it again (when i changed it to created_at) and get the same error: ERROR: column "created_at" of relation "products" does not exist – javascript2016 Sep 09 '16 at 19:58
  • Because you created the table with a `"createdAt"` column, not a `created_at` column. – mu is too short Sep 09 '16 at 20:37
  • 1
    how can I create it with the _ since its being created automatically (I don't create the createdAt column) – javascript2016 Sep 09 '16 at 21:51
  • Then you have to refer to it as `"createdAt"` (with the quotes) in your INSERT. Presumably your Sequelize model would take care of this stuff for you so why are you writing an INSERT by hand? – mu is too short Sep 09 '16 at 22:25
  • I write it by hand because if I don't, Im getting an error saying I have to do that..Alao if I refer to it as "createdAt" it also tells me that the column doesn't exist :/ – javascript2016 Sep 10 '16 at 01:46
  • Well, go into `psql` from the command line and do a `\d products` to see what the table really looks like. I suspect you're not using Sequelize properly though. – mu is too short Sep 10 '16 at 02:09

0 Answers0