eveningkid / denodb

MySQL, SQLite, MariaDB, PostgreSQL and MongoDB ORM for Deno
https://eveningkid.com/denodb-docs
MIT License
1.93k stars 129 forks source link

Duplicate key on write or update prevents other tables from syncing #151

Open sntg-p opened 3 years ago

sntg-p commented 3 years ago

Am I the only one having this problem? It seems that when syncing the tables to the database, when the constraint already exists it throws this error and just stops syncing all tables.

I'm using MariaDB so I think this could be fixed by adding the constraint if it doesn't exist like this:

ALTER TABLE `rabbits`
ADD CONSTRAINT `fk_rabbits_main_page` FOREIGN KEY IF NOT EXISTS
(`main_page_id`) REFERENCES `rabbit_pages` (`id`);

After some investigation I realised that denjucks/dex is being used for the actual query generation, maybe I should go bother there?

jrdx0 commented 3 years ago

I always have that problem when I use the drop property in the sync function. I just delete the database and I create it again. I think is more a Maria DB issue than a dex issue. :/