Ticket #1061 (closed defect: wontfix)
Undocumented: can't use orm API with --db-dry-run
|Reported by:||slinkp||Owned by:||andrew|
If a migration accesses the orm API, you get an exception.
AFAICT this is not mentioned in the docs at all.
Example - I created a schema migration where the default value for a foreign key was derived by a query:
class Migration(SchemaMigration): def forwards(self, orm): default_place_type_id = orm['streets.PlaceType'].objects.get(slug='poi').id # Adding field 'Place.place_type' db.add_column('streets_place', 'place_type', self.gf('django.db.models.fields.related.ForeignKey')(default=default_place_type_id, to=orm['streets.PlaceType']), keep_default=False)
This works fine - except that it blows up when --db-dry-run is passed.
The error message is nice and explicit, but it would be great if this was in the docs somewhere; AFAICT it is not:
AttributeError: You are in a dry run, and cannot access the ORM. Wrap ORM sections in 'if not db.dry_run:', or if the whole migration is only a data migration, set no_dry_run = True on the Migration class.
Also the no_dry_run attribute isn't mentioned in the docs.