﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
35036	sqlsequencereset needs set search_path	Ramon	nobody	"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
}}}"	Bug	closed	Database layer (models, ORM)	4.2	Normal	duplicate	sqlsequencereset postgresql15 search_path schema		Unreviewed	0	0	0	0	0	0
