Slide 1

Slide 1 text

1.7 Andrew Godwin @andrewgodwin & you

Slide 2

Slide 2 text

Andrew Godwin Author of South migrations library Hi, I'm Author of 1.7 Django migrations Generally far too involved in Django

Slide 3

Slide 3 text

Django 1.7 Migrations Scheduled release: May 15th (we'll probably miss it) App loading refactor Checks framework select_related filters Custom lookups

Slide 4

Slide 4 text

Migrations They're pretty good.

Slide 5

Slide 5 text

The (second) Plan Django Schema backend ORM Hooks South 2 Migration handling User interface Backport for 1.4 - 1.6

Slide 6

Slide 6 text

Logically Separate Schema backend ORM Hooks Migration handling User interface SchemaEditor Migrations

Slide 7

Slide 7 text

A New Format More concise Declarative Introspectable

Slide 8

Slide 8 text

Migration actions Frozen ORM

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

In-memory running Creates models from migration sets Autodetector diffs created from on-disk Used to feed SchemaEditor / ORM

Slide 11

Slide 11 text

Backwards Compatability Auto-applies first migration if tables exist Ignores South-style migrations South will start looking for south_migrations

Slide 12

Slide 12 text

App Loading Mostly internal change App objects per-app Start of long path away from settings

Slide 13

Slide 13 text

Checks Framework Proper support for project-level validation Old validation moved in Upgrade warnings now possible

Slide 14

Slide 14 text

from django.core.checks import register @register() def example_check(app_configs, **kwargs): errors = [] # ... your check logic here return errors

Slide 15

Slide 15 text

prefetch_related control Now accepts a Prefetch object Can customise order, select_related, or filter

Slide 16

Slide 16 text

Pizza.objects.prefetch_related( Prefetch( 'restaurants', queryset=Restaurant.objects.select_related('best_pizza'), ) )

Slide 17

Slide 17 text

Custom Lookups Allows for more powerful Field subclasses You can stop using .extra() and .raw() as much

Slide 18

Slide 18 text

from django.db.models import Lookup class NotEqual(Lookup): lookup_name = 'ne' def as_sql(self, qn, connection): lhs, lhs_params = self.process_lhs(qn, connection) rhs, rhs_params = self.process_rhs(qn, connection) params = lhs_params + rhs_params return '%s <> %s' % (lhs, rhs), params

Slide 19

Slide 19 text

Important Upgrade Notes

Slide 20

Slide 20 text

Fields need deconstruct() It's a required new method for all fields.

Slide 21

Slide 21 text

syncdb is deprecated Use migrate (old apps will still work)

Slide 22

Slide 22 text

initial_data is dead Use data migrations and the ORM instead

Slide 23

Slide 23 text

Django 1.8? LTS Migrations for contrib apps PostgreSQL improvements?

Slide 24

Slide 24 text

Thanks. @andrewgodwin aeracode.org