Opened 3 years ago

Closed 3 years ago

#33652 closed New feature (wontfix)

Skip ExclusionConstraint on non-PostgreSQL databases.

Reported by: hottwaj Owned by: nobody
Component: Migrations Version: dev
Severity: Normal Keywords: postgres exclusion constraint
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Exclusion constraints are only supported by postgres, and using them with e.g. a sqlite backend causes an exception during migrations when django attempts to insert them into the DB.

Could exclusion constraints be skipped when migrations are run for non-postgres backends instead? Perhaps with a warning that they are being skipped?

This would help in situations where multiple backends are used for testing/prototyping purposes

Change History (1)

comment:1 by Mariusz Felisiak, 3 years ago

Component: Database layer (models, ORM)Migrations
Resolution: wontfix
Status: newclosed
Summary: migrations: skip insertion of exclusion constraints when not using postgresSkip ExclusionConstraint on non-PostgreSQL databases.

Thanks for this report. We strongly recommend that you use the same database for testing and a real-life apps. There are many differences and you may encounter unexpected issues by using a different backend for testing. Therefore, we don't want to encourage users to do this by automatically skipping PostgreSQL-specific features. If you really have to do this you can skip PostgreSQL constraints/indexes in migration files, e.g.

class Migration(migrations.Migration):

    dependencies = [
        ('test_33652', '0001_initial'),
    ]

    if connection.vendor == 'postgresql':
        operations = [
            migrations.AddConstraint(
                model_name='hotelreservation',
                constraint=django.contrib.postgres.constraints.ExclusionConstraint(condition=models.Q(('cancelled', False)), expressions=[('room', '=')], name='exclude_overlapping_reservations'),
            ),
        ]
    else:
        operations = []
Note: See TracTickets for help on using tickets.
Back to Top