[Django] #36985: Reversing CreateExtension throws error on non-postgresql database

3 views
Skip to first unread message

Django

unread,
Mar 13, 2026, 8:24:34 AM (5 days ago) Mar 13
to django-...@googlegroups.com
#36985: Reversing CreateExtension throws error on non-postgresql database
-----------------------+--------------------------------------------
Reporter: tahme | Type: Bug
Status: new | Component: contrib.postgres
Version: 6.0 | Severity: Normal
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------+--------------------------------------------
When run on sqlite, a migration using postgres CreateExtension will skip
creating the extension. Trying to reverse the migration throws an error:
{{{
django.db.utils.OperationalError: no such table: pg_extension
}}}

I assume this is because CreateExtension.database_forwards checks
schema_editor.connection.vendor != "postgresql" but
CreateExtension.database_backwards does not.

Minimal migration example:
{{{
from django.db import migrations
from django.contrib.postgres.operations import CreateExtension

class Migration(migrations.Migration):
dependencies = []

operations = [
CreateExtension("pg_trgm")
]
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/36985>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Mar 16, 2026, 5:34:33 AM (3 days ago) Mar 16
to django-...@googlegroups.com
#36985: Reversing CreateExtension throws error on non-postgresql database
----------------------------------+--------------------------------------
Reporter: Jori Niemi | Owner: (none)
Type: Bug | Status: new
Component: contrib.postgres | Version: 6.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+--------------------------------------
Comment (by Lakshya Prasad):

I can reproduce this issue locally. Reversing CreateExtension on a
non-PostgreSQL database raises an error. The operation should likely
be skipped when the connection vendor is not PostgreSQL.

I’d like to work on a fix if the ticket is accepted.
--
Ticket URL: <https://code.djangoproject.com/ticket/36985#comment:1>

Django

unread,
2:33 PM (5 hours ago) 2:33 PM
to django-...@googlegroups.com
#36985: Reversing CreateExtension throws error on non-postgresql database
--------------------------------------+------------------------------------
Reporter: Jori Niemi | Owner: (none)
Type: Cleanup/optimization | Status: new
Component: contrib.postgres | Version: 6.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Jacob Walls):

* easy: 0 => 1
* stage: Unreviewed => Accepted
* type: Bug => Cleanup/optimization

Comment:

Ok, let's have this. Interestingly, this graceful skip in the forward
direction was only added for Django's own test suite in
36e90d1f45a13f53ce25fdc2d9c04433b835c9af.
--
Ticket URL: <https://code.djangoproject.com/ticket/36985#comment:2>
Reply all
Reply to author
Forward
0 new messages