#35902: migrate --syncdb and TEST_MIGRATE break for models with fields requiring
extensions, and custom collation or types on Postgres
--------------------------------+------------------------------------------
     Reporter:  wadhah mahrouk  |                    Owner:  wadhah mahrouk
         Type:  Bug             |                   Status:  assigned
    Component:  Migrations      |                  Version:  5.1
     Severity:  Normal          |               Resolution:
     Keywords:                  |             Triage Stage:  Accepted
    Has patch:  1               |      Needs documentation:  0
  Needs tests:  0               |  Patch needs improvement:  1
Easy pickings:  0               |                    UI/UX:  0
--------------------------------+------------------------------------------
Changes (by Simon Charette):

 * component:  Database layer (models, ORM) => Migrations
 * easy:  1 => 0
 * needs_better_patch:  0 => 1
 * stage:  Unreviewed => Accepted
 * summary:
     Postgres extensions not enabled in test DB when running pytest --no-
     migrations
     =>
     migrate --syncdb and TEST_MIGRATE break for models with fields
     requiring extensions, and custom collation or types on Postgres
 * type:  Uncategorized => Bug

Comment:

 I believe this is a problem with `migrate --syncdb` and not test database
 creation per se. Test database creation is meant to do one thing only;
 create an empty database with the proper name and delegate everything else
 to `migrate`.

 The existence of extensions, which is tracked by database migration
 operations, is not different from other Postgres feature that the schema
 might require to create indices and fields such as collations and custom
 types.

 The ''problem'' here is that `migrate --run-syncdb`, which is relied upon
 by
 
[https://github.com/django/django/blob/40bfd7b09aa0907b143e96f0b055538f476e544e/django/db/backends/base/creation.py#L68-L84
 test database creation], has absolutely no knowledge of database migration
 operations that don't relate directly to models by design. All it does is
 
[https://github.com/django/django/blob/40bfd7b09aa0907b143e96f0b055538f476e544e/django/core/management/commands/migrate.py#L434-L489
 create models].

 To confirm the issue is not specific to `TEST_MIGRATE=False` try settings
 `MIGRATION_MODULES` entries to `None` for each of your `INSTALLED_APPS`
 and running `migrate --sync-db` against a fresh database, you should see
 the exact same failure.

 Even if we wanted to only solve the problem for `TEST_MIGRATE=False` the
 proposed solution seems brittle as it requires the migrations to be fully
 applied on the non-test database (for extensions to exists) which might
 the case for local development setups but definitely not the case on CI
 setups where only the test database is created.
-- 
Ticket URL: <https://code.djangoproject.com/ticket/35902#comment:1>
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 visit 
https://groups.google.com/d/msgid/django-updates/01070193171944ac-b5a979fe-93de-4e73-a0cd-63333d9dfcef-000000%40eu-central-1.amazonses.com.

Reply via email to