saleor
saleor copied to clipboard
How to Fix bug when i migrate: psycopg2.errors.UndefinedFunction: function gen_random_uuid() does not exist
Discussed in https://github.com/saleor/saleor/discussions/10644
Originally posted by yetqdn September 13, 2022
(saleor-venv) root@vps:/home/saleor# python manage.py migrate 2022-09-07 14:06:34,394 WARNING saleor.core.jwt_manager RSA_PRIVATE_KEY is missing. Using temporary key for local development with DEBUG mode. [PID:109884:MainThread] 2022-09-07 14:06:34,639 WARNING py.warnings /home/saleor/saleor/urls.py:60: UserWarning: The debug toolbar was not installed. Ignore the error. settings.py should already have warned the user about it. warnings.warn( [PID:109884:MainThread] Operations to perform: Apply all migrations: account, app, attribute, auth, channel, checkout, contenttypes, core, csv, discount, django_celery_beat, django_prices_openexchangerates, django_prices_vatlayer, giftcard, invoice, menu, order, page, payment, plugins, product, schedulers, shipping, site, sites, thumbnail, warehouse, webhook Running migrations: Applying account.0068_user_uuid...Traceback (most recent call last): File "/home/saleor/saleor-venv/lib/python3.9/site-packages/django/db/backends/utils.py", line 87, in _execute return self.cursor.execute(sql) psycopg2.errors.UndefinedFunction: function gen_random_uuid() does not exist HINT: No function matches the given name and argument types. You might need to add explicit type casts.
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/saleor/manage.py", line 10, in
Hello @yetqdn 👋
I have to ask you to do two things:
- Please follow the template for an issue.
- Please format the code with "```" next time you post it.
I fixed it by deleting the error files in the migrations folder, but I'm not sure what errors or missing features will arise later when I use it
@yetqdn
I'm getting the same error.
Applying account.0068_user_uuid...Traceback (most recent call last):
File "/home/admin/.virtualenvs/mysite/lib/python3.8/site-packages/django/db/backends/utils.py", line 82, in _execute
return self.cursor.execute(sql)
psycopg2.errors.UndefinedFunction: function gen_random_uuid() does not exist
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
What to do?
EDIT:
Using Saleor 3.7, Python 3.8
It seems we need to load the pgcrypto extension in the current database/schema before applying the function.
Example:
Execute:
CREATE EXTENSION pgcrypto;
Before applying the 'broken' migration file (saleor/account/migrations/0068_user_uuid.py) which contains this sql statement:
ALTER TABLE account_user ALTER COLUMN uuid SET DEFAULT gen_random_uuid();
EDIT
I solved the error by manually logging into the saleor database and creating the extension, then running the python manage.py migrate
again.
@yetqdn @peelar
I hope you guys don't mind I submitted a bug report based on your comment, peelar. Hi @roperi @peelar, Thanks for your comment, In the last few days I try to do this way: "CREATE EXTENSION pgcrypto;" but it did not work. Then I deleted the error file 068 and all files behind it. I did the syntax migrate and it was successful. Then I copied the deleted files one by one and migrated successfully. However, I thought I made the mistake of not selecting the update branch. So I deleted and reinstall it. I did syntax " git checkout -b 3.7 remotes/origin/3.7" for version saleor3.7.3 and it installed successfully without any errors Best regrads!
Hello @yetqdn and @roperi
Thanks for your reports. We added it to our backlog and I will let you know as soon as it's fixed.
Have a nice day 🌻
@yetqdn ,
Did you first connect to the saleor database with \c saleor
before executing CREATE EXTENSION pgcrypto;
? The extension has to be created within the Saleor database.
Thanks, @peelar !
@roperi I sign in Postgresql with user postgres and make CREATE EXTENSION pgcrypto; Thank you for the helpful advise!
I think this can be solved by executing an SQL statement for creating the extension via psycopg2. I can raise a PR for this.
Closing, as the solution was posted in https://github.com/saleor/saleor/issues/10678/.