0

I just cloned my project from my github account. I spin the server and i'm getting triggerUncaughtException(err, true /* fromPromise */); name: 'SequelizeDatabaseError', parent: Error: Cannot drop table 'dealers' referenced by a foreign key constraint 'cars_ibfk_1' on table 'cars'. sql: 'DROP TABLE IF EXISTS Dealers;', parameters: undefined

I expected to get a table created in my local mysql database with no errors. I tried checking the connection host if it matches one with my installed mysql connection.

  • Would you mind posting your model initialization/configuration where your application is creating your tables? Based upon your description, it sounds like you're using `Model.sync`, which can sometimes attempt to forcefully delete tables before recreating them. Please ensure the order/flow of the code is clear to the reader too. Thanks! – Andrew T Mar 20 '23 at 21:12

1 Answers1

0

I fixed the error. It had to do with the order I created the tables. so I had two tables 'user' and 'cars'. The cars table belonged to the user table. Since I already worked on the code from another computer, I've created the user table before the cars table but I called the car.sync() before the user. Running npm start after importing the project in another project caused the error. You can't create a child table 'cars' before the parent table 'user'.

Initially, it was:

await Car.sync();
await User.sync();

So I corrected it to:

await User.sync();
await Car.sync();
Tyler2P
  • 2,324
  • 26
  • 22
  • 31