10 examples of 'django fake migration' in Python

Every line of 'django fake migration' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
704@override_settings(
705 INSTALLED_APPS=[
706 "migrations.migrations_test_apps.migrated_app",
707 "migrations.migrations_test_apps.migrated_unapplied_app",
708 "migrations.migrations_test_apps.unmigrated_app",
709 ],
710)
711def test_regression_22823_unmigrated_fk_to_migrated_model(self):
712 """
713 Assuming you have 3 apps, `A`, `B`, and `C`, such that:
714
715 * `A` has migrations
716 * `B` has a migration we want to apply
717 * `C` has no migrations, but has an FK to `A`
718
719 When we try to migrate "B", an exception occurs because the
720 "B" was not included in the ProjectState that is used to detect
721 soft-applied migrations (#22823).
722 """
723 call_command("migrate", "migrated_unapplied_app", stdout=io.StringIO())
724
725 # unmigrated_app.SillyModel has a foreign key to 'migrations.Tribble',
726 # but that model is only defined in a migration, so the global app
727 # registry never sees it and the reference is left dangling. Remove it
728 # to avoid problems in subsequent tests.
729 del apps._pending_operations[('migrations', 'tribble')]
229def apply_migration(self, state, migration, fake=False, fake_initial=False):
230 """
231 Runs a migration forwards.
232 """
233 if self.progress_callback:
234 self.progress_callback("apply_start", migration, fake)
235 if not fake:
236 if fake_initial:
237 # Test to see if this is an already-applied initial migration
238 applied, state = self.detect_soft_applied(state, migration)
239 if applied:
240 fake = True
241 if not fake:
242 # Alright, do it normally
243 with self.connection.schema_editor(atomic=migration.atomic) as schema_editor:
244 state = migration.apply(state, schema_editor)
245 # For replacement migrations, record individual statuses
246 if migration.replaces:
247 for app_label, name in migration.replaces:
248 self.recorder.record_applied(app_label, name)
249 else:
250 self.recorder.record_applied(migration.app_label, migration.name)
251 # Report progress
252 if self.progress_callback:
253 self.progress_callback("apply_success", migration, fake)
254 return state
9def forwards(self, orm):
10 ProjectKey = orm['sentry.ProjectKey']
11 ProjectKey.objects.filter(
12 user__isnull=False,
13 ).update(user=None)
226def pre_1_6(self, target, db):
227 # Override Django's get_apps call temporarily to only load from the
228 # current app
229 old_get_apps = models.get_apps
230 new_get_apps = lambda: [models.get_app(target.app_label())]
231 models.get_apps = new_get_apps
232 loaddata.get_apps = new_get_apps
233 try:
234 call_command('loaddata', 'initial_data', verbosity=self.verbosity, database=db)
235 finally:
236 models.get_apps = old_get_apps
237 loaddata.get_apps = old_get_apps
47def get_migration(self):
48 """ Get a single migration (import form file)
49
50 :return:
51 """
52 pass
56def test_migrations(self, db, settings):
57 settings.MIGRATION_MODULES = {'testapp': 'tests.testapp.migrations'}
58 call_command('makemigrations', 'testapp')
59 with open(os.path.join(settings.BASE_DIR, 'testapp/migrations/0001_initial.py')) as f:
60 migration = f.read()
61 shutil.rmtree(os.path.join(settings.BASE_DIR, 'testapp/migrations'))
62 assert "'managed': False," in migration
63 assert "'db_table': 'salesforce\".\"number_object__c'," in migration
220@override_settings(MIGRATION_MODULES={
221 'fields':
222 'tests.fields.test_migrations_normal_to_encrypted'
223})
224def test_makemigrations_no_changes(self):
225 out = six.StringIO()
226 call_command('makemigrations', '--dry-run', 'fields', stdout=out)
227 self.assertIn("No changes detected in app 'fields'", out.getvalue())
76def run_migration(self, migration):
77 migration_function = self.direction(migration)
78 south.db.db.start_transaction()
79 try:
80 migration_function()
81 south.db.db.execute_deferred_sql()
82 except:
83 south.db.db.rollback_transaction()
84 if not south.db.db.has_ddl_transactions:
85 print self.run_migration_error(migration)
86 raise
87 else:
88 south.db.db.commit_transaction()
2400def test_run_python_noop(self):
2401 """
2402 #24098 - Tests no-op RunPython operations.
2403 """
2404 project_state = ProjectState()
2405 new_state = project_state.clone()
2406 operation = migrations.RunPython(migrations.RunPython.noop, migrations.RunPython.noop)
2407 with connection.schema_editor() as editor:
2408 operation.database_forwards("test_runpython", editor, project_state, new_state)
2409 operation.database_backwards("test_runpython", editor, new_state, project_state)
39def test_migrate(self):
40 with capture_stdout():
41 call_command('migrate', interactive=False)

Related snippets