#35036: sqlsequencereset needs set search_path
-------------------------------------+-------------------------------------
Reporter: Ramon | Owner: nobody
Type: Bug | Status: new
Component: Database | Version: 4.2
layer (models, ORM) | Keywords: sqlsequencereset
Severity: Normal | postgresql15 search_path schema
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
These management commands fail:
{{{
./manage.py sqlsequencereset | ./manage.py dbshell
}}}
Generated SQL from sqlsequencereset (Partial4x4 is from my application):
{{{
BEGIN;
SELECT setval(pg_get_serial_sequence('"Partial4x4_partial4x4"','id'),
coalesce(max("id"), 1), max("id") IS NOT null) FROM
"Partial4x4_partial4x4";
COMMIT;
}}}
Example of error:
{{{
BEGIN
ERROR: relation "Partial4x4_partial4x4" does not exist
LINE 1: ...alesce(max("id"), 1), max("id") IS NOT null) FROM "Partial4x...
^
ROLLBACK
}}}
PostgreSQL 15 blocks use of the public schema. This requires use of
database connection options to set the search path.
settings:
{{{
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'OPTIONS': {'options': '-c search_path=your_db_schema'}, #
critical
'NAME': 'your_db_name',
'USER': 'your_db_user',
'PASSWORD': 'your_db_password',
'HOST': 'localhost',
'PORT': '5432'
}
}
}}}
The SQL generated by sqlsequencereset fails because of not inserting a
command to set the search path.
Corrected SQL:
{{{
set search_path="your_db_schema";
BEGIN;
SELECT setval(pg_get_serial_sequence('"Partial4x4_partial4x4"','id'),
coalesce(max("id"), 1), max("id") IS NOT null) FROM
"Partial4x4_partial4x4";
COMMIT;
}}}
Containment that works for me:
{{{
(echo 'set search_path="your_db_schema";'; /manage.py sqlsequencereset
Partial4x4) | ./manage.py dbshell
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/35036>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/0107018c673d0390-91bd916b-8f55-4e7f-8004-6e6eb0646c00-000000%40eu-central-1.amazonses.com.