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

Changede UUIDField data type to translate to VARCHAR(36) #105

Conversation

MarekovicJan
Copy link

Hi,

I was playing with django-snowflake library and tried to connect one of my other projects to Snowflake.
On that project our models PKs are mainly UUIDs, so when I ran the migration I got an error saying that
UUID string is too long for a VARCHAR(32) field and I started looking into the Snowflake documentation
and saw that Snowflake actually usses VARCHAR(36) for UUID fields (here is also a link to the docs: https://docs.snowflake.com/en/sql-reference/functions/uuid_string). Once I changed that in my library it fixed the problem.

@timgraham
Copy link
Collaborator

It seems your project uses Snowflake's UUID_STRING() function to generate values, but this isn't what Django expects. Django stores the UUID value without dashes (value.hex).

@Tatsh
Copy link

Tatsh commented Feb 6, 2025

I support the idea behind this change. But I also need the backend to save the UUID with hyphens. Unfortunately I think monkeypatching UUIDField.get_db_prep_value is required so that str(uuid) can be used in place .hex.

@timgraham
Copy link
Collaborator

I'd recommend using a custom field if you need to store a UUID with dashes,

@timgraham timgraham closed this Feb 6, 2025
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.

3 participants