#22983: Invalid import in a squashed migration of migrations having RunPython
---------------------------------+----------------------------------------
     Reporter:  riklaunim        |                    Owner:  andrewgodwin
         Type:  Bug              |                   Status:  assigned
    Component:  Migrations       |                  Version:  1.7-rc-1
     Severity:  Release blocker  |               Resolution:
     Keywords:                   |             Triage Stage:  Accepted
    Has patch:  0                |      Needs documentation:  0
  Needs tests:  0                |  Patch needs improvement:  0
Easy pickings:  0                |                    UI/UX:  0
---------------------------------+----------------------------------------

Comment (by generalov):

 I put all data migration functions in separate module
 `migrations/datamigrations/__init__.py` then import code from it to
 migration module.
 {{{
 # 0002_some_migration.py
 from . import datamigrations

 class Migration(migrations.Migration):
     operations = [
         migrations.RunPython(datamigrations.fix_data),
 }}}

 In this case the `squashmigrations` builds the following result:
 {{{
 import project.app.migrations.datamigrations

 class Migration(migrations.Migration):
     operations = [
         migrations.RunPython(
             code=project.app.migrations.datamigrations.fill_serial,
             reverse_code=None,
             atomic=True,
         ),
 }}}

 The code looks bit ugly but it works without any modifications.

 I create `datamigration` as package instead of just file module beacause
 otherwise `manage.py squashmigrations ..` fails with exception
 `django.db.migrations.loader.BadMigrationError: Migration datamigrations
 in app app has no Migration class`

-- 
Ticket URL: <https://code.djangoproject.com/ticket/22983#comment:10>
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 post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/067.a0a9a70b85fe0fac3682e83e75fcd7b6%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to