Opened 7 years ago

Closed 7 years ago

#27892 closed New feature (wontfix)

Add a way to specify "independent" migrations

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

Description

Currently django uses MigrationGraph and decides the order of migrations before applying them. When writing migrations manually, users should specify dependencies or run_before for a migration so that django can decide when to apply it.

This becomes a problem with independent migrations like this

from django.contrib.postgres.operations import UnaccentExtension
from django.db import migrations

class Migration(migrations.Migration):
    operations = [
        UnaccentExtension(),
    ]

Is it possible to have independent field on Migration class, so that these migrations will be applied first then django can resume with migrations as usual.

Change History (5)

comment:1 by Tim Graham, 7 years ago

These migrations aren't independent -- they need to be run in a certain order (first, as you said). Why is it a problem to specify dependencies or run_before in your use case?

comment:2 by ChillarAnand, 7 years ago

This migration is temporary. It is better not to use dependencies as it becomes a problem when removing if new migrations pile up.

run_before doesn't seem to work as expected in this case.

    run_before = [
        ('book', '0001_initial'),
    ]

makemigrations fails with

Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    execute_from_command_line(sys.argv)
  File "/home/chillaranand/projects/django/django/core/management/__init__.py", line 354, in execute_from_command_line
    utility.execute()
  File "/home/chillaranand/projects/django/django/core/management/__init__.py", line 348, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/chillaranand/projects/django/django/core/management/base.py", line 280, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/chillaranand/projects/django/django/core/management/base.py", line 327, in execute
    output = self.handle(*args, **options)
  File "/home/chillaranand/projects/django/django/core/management/commands/makemigrations.py", line 93, in handle
    loader.check_consistent_history(connection)
  File "/home/chillaranand/projects/django/django/db/migrations/loader.py", line 293, in check_consistent_history
    connection.alias,
django.db.migrations.exceptions.InconsistentMigrationHistory: Migration book.0001_initial is applied before its dependency book.unaccent on database 'default'.

comment:3 by Tim Graham, 7 years ago

I don't understand what you mean by the first two sentences in comment 2.

comment:4 by Simon Charette, 7 years ago

This migration is temporary.

It isn't. All database created from scratch will require this operation to be run before they can rely on the extension?

comment:5 by Tim Graham, 7 years ago

Resolution: wontfix
Status: assignedclosed
Summary: Independent migrationsAdd a way to specify "independent" migrations
Note: See TracTickets for help on using tickets.
Back to Top