MCPcopy
hub / github.com/django/django / apply_migration

Method apply_migration

django/db/migrations/executor.py:241–266  ·  view source on GitHub ↗

Run a migration forwards.

(self, state, migration, fake=False, fake_initial=False)

Source from the content-addressed store, hash-verified

239 return state
240
241 def apply_migration(self, state, migration, fake=False, fake_initial=False):
242 """Run a migration forwards."""
243 migration_recorded = False
244 if self.progress_callback:
245 self.progress_callback("apply_start", migration, fake)
246 if not fake:
247 if fake_initial:
248 # Test to see if this is an already-applied initial migration
249 applied, state = self.detect_soft_applied(state, migration)
250 if applied:
251 fake = True
252 if not fake:
253 # Alright, do it normally
254 with self.connection.schema_editor(
255 atomic=migration.atomic
256 ) as schema_editor:
257 state = migration.apply(state, schema_editor)
258 if not schema_editor.deferred_sql:
259 self.record_migration(migration.app_label, migration.name)
260 migration_recorded = True
261 if not migration_recorded:
262 self.record_migration(migration.app_label, migration.name)
263 # Report progress
264 if self.progress_callback:
265 self.progress_callback("apply_success", migration, fake)
266 return state
267
268 def record_migration(self, app_label, name, forward=True):
269 migration = self.loader.disk_migrations.get((app_label, name))

Calls 4

detect_soft_appliedMethod · 0.95
record_migrationMethod · 0.95
schema_editorMethod · 0.80
applyMethod · 0.45