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

Error: Multiple primary key defined. #165

Closed boojack closed 2 years ago

boojack commented 3 years ago

The current code:

db.link([User, Note]);
await Note.drop();
await User.drop();
await db.sync();

But if I delete the await Note.drop(); await User.drop();, the problem will throw error Error: Multiple primary key defined.

It looks like that I have to empty the database before connect to MySQL. It's really not nice :( How can I do this?

JonasPardon commented 3 years ago

Having the same issue here.

I can create a new model, link and sync it to the database without issues.

If I restart my deno app, it will once again link and sync, but will fail when syncing since it's just trying to recreate my (already present) model in the database.

This is my first time using denodb, so I might be overlooking something here, I'm not sure. Documentation doesn't mention anything about adding fields to models.

I'm a Laravel developer used to database migrations, so not sure how this is handled here.

boojack commented 2 years ago

Looks like no response ;)

JonasPardon commented 2 years ago

Pretty weird IMO to close an issue and mark it as completed simply because there's no response to it.

Not getting a response to something does not equal the problem no longer existing. I would leave this open until actually resolved.

akatechis commented 2 years ago

I'm having this issue as well. It would be nice to simply call db.sync() unconditionally, and let the library determine which model tables need to be created, and ignore any that already exist or even better, check the existing ones for changes to the schema and synchronize those changes as well!

Or, if this is working as intended, it should be mentioned in the docs, that db.sync() is only meant to be called from a one-time set up script, and any further changes need to be done via migration scripts.