0

Error occurs when trying to run python manage.py migrate in a django application.
complete code

git clone https://github.com/saleor/saleor.git  
cd saleor  
python manage.py migrate  

Raised error psycopg2.errors.UndefinedFunction: function gen_random_uuid() does not exist LINE 1: UPDATE "account_user" SET "uuid" = GEN_RANDOM_UUID()

but works in running postgres
I created extention in postgres, commited that. Here is code to create extention in postgres and call the function which is raising the above error, so this function is working but I am unable to call through django when I use postgres db

postgres=# `SELECT gen_random_uuid()`;  
           gen_random_uuid  

Output is

--------------------------------------  
 f36d69b7-5681-4b92-b37e-9b0217b7d829  
(1 row)  

I tried to run this in docker and it works as expected

git clone https://github.com/saleor/saleor.git    
cd saleor  
python manage.py migrate 

It works fine with docker.

I tried some other commands to check version and system, here PostgreSQL 15.1 (Ubuntu 15.1-1.pgdg20.04+1) on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0, 64-bit Thanks for comment. – Garuda

pg_lsclusters 
15 main 5432 online postgres /var/lib/postgresql/15/main/var/log/postgresql/postgresql-15-main.log

----------------------------------------------------------
PostgreSQL 15.1 (Ubuntu 15.1-1.pgdg20.04+1) on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0, 64-bit 

Any help will be appreciated.

Garuda
  • 46
  • 7
  • Is it possible you're running Django on a different server? – Tim Roberts Jan 22 '23 at 06:33
  • Thanks for comment. But you can check settings.py , AFAIK this is not the real issue. – Garuda Jan 22 '23 at 07:02
  • Does this answer your question? [Why "PG::UndefinedFunction: ERROR: function gen\_random\_uuid() does not exist" on new server but not on old?](https://stackoverflow.com/questions/74527555/why-pgundefinedfunction-error-function-gen-random-uuid-does-not-exist-on) – ErikR Jan 22 '23 at 07:21
  • 2
    You will have to check your Postgres version, as Postgres introduced this in version 13. Any version before this, you had to use external modules. See https://stackoverflow.com/a/74527757/6383431 – ErikR Jan 22 '23 at 07:22
  • PostgreSQL 15.1 (Ubuntu 15.1-1.pgdg20.04+1) on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0, 64-bit Thanks for comment. – Garuda Jan 22 '23 at 08:04
  • pg_lsclusters 15 main 5432 online postgres /var/lib/postgresql/15/main /var/log/postgresql/postgresql-15-main.log – Garuda Jan 22 '23 at 08:06
  • You will need to specify more about your setup, since in your original post you mention that `it doesn't work when running` and `but works in running` and `it works fine with docker`. There is also an issue on the Saleor-issue-tracker regarding this, you might have some success if you follow the workaround there. https://github.com/saleor/saleor/issues/10648#issuecomment-1249507171 – ErikR Jan 22 '23 at 15:12
  • It HAS to be the case that you're using two different servers here. "gen_random_uuid" was added in Postgres 13. Your Django app must be configured to use an older one. – Tim Roberts Jan 23 '23 at 21:16

0 Answers0