Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Vec<u8> primary key #287

Merged
merged 2 commits into from
Nov 2, 2021
Merged

Support Vec<u8> primary key #287

merged 2 commits into from
Nov 2, 2021

Conversation

billy1624
Copy link
Member

@billy1624 billy1624 self-assigned this Nov 2, 2021
@billy1624
Copy link
Member Author

Hey @tyt2y3, I was wondering why ColumnType::Binary is defined as without length in sea-orm?

Because of that, I can't seems to get around this.

Error: Exec("error returned from database: 1170 (42000): BLOB/TEXT column 'id' used in key specification without a key length")

@tyt2y3
Copy link
Member

tyt2y3 commented Nov 2, 2021

The BYTEA type in Postgres does not have a length.

@tyt2y3
Copy link
Member

tyt2y3 commented Nov 2, 2021

@robot-head can you share your schema definition? I bet the index should have a key length

@billy1624
Copy link
Member Author

Hey @tyt2y3, I was wondering why ColumnType::Binary is defined as without length in sea-orm?

Because of that, I can't seems to get around this.

Error: Exec("error returned from database: 1170 (42000): BLOB/TEXT column 'id' used in key specification without a key length")

Btw... this only failed on MySQL & MariaDB. Postgres is working perfectly

@tyt2y3
Copy link
Member

tyt2y3 commented Nov 2, 2021

Okay, then we should use sea_query::ColumnType::Binary(Some(1024)) explicitly for the test case.

@billy1624
Copy link
Member Author

Well, can we default 1024 it inside SeaORM?

For MySQL & MariaDB only and leave Postgres untouched?

@tyt2y3
Copy link
Member

tyt2y3 commented Nov 2, 2021

Edited

@billy1624
Copy link
Member Author

Okay, then we should use sea_query::ColumnType::Binary(Some(1024)) explicitly for the test case.

That would work but how about ordinary user that want to use create_table_from_entity on MySQL & MariaDB? They will fall into this trap as well if they happen to use Vec<u8> (blob db type) as primary key.

@tyt2y3
Copy link
Member

tyt2y3 commented Nov 2, 2021

Looks good. Anything missing? We are about to make a minor release.

@billy1624 billy1624 marked this pull request as ready for review November 2, 2021 14:25
@billy1624
Copy link
Member Author

Go for it

@tyt2y3 tyt2y3 merged commit e2d4ccf into master Nov 2, 2021
@tyt2y3 tyt2y3 deleted the vec-u8-primary-key branch November 2, 2021 16:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for BYTEA Postgres primary keys
2 participants