In [1]: from django.db import connection In [2]: from django.db.migrations.executor import MigrationExecutor In [3]: executor = MigrationExecutor(connection) In [4]: import cProfile In [5]: leaves = executor.loader.graph.leaf_nodes() In [6]: cProfile.runctx('executor.migrate(leaves)', globals(), locals()) 92809573 function calls (88936382 primitive calls) in 179.169 seconds Ordered by: standard name ncalls tottime percall cumtime percall filename:lineno(function) 37005 0.176 0.000 0.220 0.000 :172(__init__) 37005 0.271 0.000 0.291 0.000 :192(acquire) 37005 0.177 0.000 0.191 0.000 :217(release) 37005 0.076 0.000 0.091 0.000 :2187(_sanity_check) 37005 0.367 0.000 1.774 0.000 :2240(_gcd_import) 31694 0.066 0.000 0.130 0.000 :2264(_handle_fromlist) 37005 0.336 0.000 0.556 0.000 :274(_get_module_lock) 37005 0.027 0.000 0.027 0.000 :288(cb) 37005 0.190 0.000 1.250 0.000 :293(_lock_unlock_module) 1 0.500 0.500 179.169 179.169 :1() 4064 0.063 0.000 0.347 0.000 __init__.py:1062(__init__) 37005 1.425 0.000 2.393 0.000 __init__.py:137(__init__) 145818 1.751 0.000 5.746 0.000 __init__.py:204(__reduce__) 15847 0.063 0.000 0.151 0.000 __init__.py:35(__getattr__) 37005 1.904 0.000 3.411 0.000 __init__.py:364(deconstruct) 309849 4.291 0.000 7.197 0.000 __init__.py:41(__init__) 105704 0.219 0.000 0.299 0.000 __init__.py:45(__getattr__) 1511 0.019 0.000 0.074 0.000 __init__.py:457(__init__) 166 0.000 0.000 0.000 0.000 __init__.py:460(__eq__) 25667 0.056 0.000 0.077 0.000 __init__.py:466(__lt__) 1511 0.009 0.000 0.024 0.000 __init__.py:482(most_common) 1511 0.010 0.000 0.055 0.000 __init__.py:526(update) 4064 0.007 0.000 0.007 0.000 __init__.py:533(validators) 1181043 8.670 0.000 10.389 0.000 __init__.py:62(__setitem__) 37005 0.247 0.000 0.407 0.000 __init__.py:652(set_attributes_from_name) 37005 0.197 0.000 2.003 0.000 __init__.py:660(contribute_to_class) 23197 0.012 0.000 0.012 0.000 __init__.py:671(get_attname) 23197 0.050 0.000 0.062 0.000 __init__.py:674(get_attname_column) 13808 0.031 0.000 0.031 0.000 __init__.py:679(get_cache_name) 31585 0.085 0.000 0.097 0.000 __init__.py:76(__delitem__) 8555682 5.431 0.000 5.431 0.000 __init__.py:87(__iter__) 37005 0.175 0.000 1.981 0.000 __init__.py:91(import_module) 15847 0.094 0.000 1.031 0.000 __init__.py:911(__init__) 15847 0.112 0.000 1.653 0.000 __init__.py:933(deconstruct) 15847 0.100 0.000 0.825 0.000 __init__.py:969(contribute_to_class) 755 0.001 0.000 0.002 0.000 _collections_abc.py:434(keys) 145818 0.285 0.000 0.423 0.000 _collections_abc.py:438(items) 878941 1.331 0.000 2.018 0.000 _collections_abc.py:442(values) 1025514 0.824 0.000 0.824 0.000 _collections_abc.py:456(__init__) 156338 0.056 0.000 0.119 0.000 _collections_abc.py:475(__iter__) 1055648 1.970 0.000 2.766 0.000 _collections_abc.py:496(__iter__) 7312441 8.725 0.000 13.241 0.000 _collections_abc.py:511(__iter__) 309849 1.513 0.000 2.466 0.000 _collections_abc.py:575(update) 1 0.000 0.000 0.000 0.000 _collections_abc.py:85(__subclasshook__) 2 0.000 0.000 0.000 0.000 _collections_abc.py:88() 1 0.000 0.000 0.000 0.000 _weakrefset.py:36(__init__) 115548 0.228 0.000 0.228 0.000 _weakrefset.py:70(__contains__) 1 0.000 0.000 0.000 0.000 _weakrefset.py:81(add) 76276 0.367 0.000 0.596 0.000 abc.py:178(__instancecheck__) 1 0.000 0.000 0.000 0.000 abc.py:194(__subclasscheck__) 15847 0.028 0.000 0.073 0.000 base.py:115() 15847 0.022 0.000 0.066 0.000 base.py:124() 15847 0.066 0.000 0.066 0.000 base.py:166() 100393 0.406 0.000 9.090 0.000 base.py:291(add_to_class) 15847 0.423 0.000 5.087 0.000 base.py:298(_prepare) 52852 0.030 0.000 0.030 0.000 base.py:327() 31694 3.262 0.000 3.262 0.000 base.py:43(subclass_exception) 15847 1.179 0.000 24.347 0.002 base.py:71(__new__) 15847 0.037 0.000 0.045 0.000 base.py:76() 843874 0.430 0.000 0.430 0.000 config.py:143(check_models_ready) 2543 0.012 0.000 0.015 0.000 config.py:151(get_model) 50 0.000 0.000 0.001 0.000 config.py:16(__init__) 5641150 13.366 0.000 27.974 0.000 config.py:164(get_models) 3564 0.015 0.000 0.049 0.000 contextlib.py:124(helper) 3564 0.028 0.000 0.033 0.000 contextlib.py:37(__init__) 3564 0.007 0.000 0.017 0.000 contextlib.py:57(__enter__) 3564 0.018 0.000 26.144 0.007 contextlib.py:63(__exit__) 3198136/3020 10.298 0.000 46.563 0.015 copy.py:137(deepcopy) 2687018 0.620 0.000 0.620 0.000 copy.py:192(_deepcopy_atomic) 219482 1.534 0.000 1.958 0.000 copy.py:223(_deepcopy_tuple) 72154 0.975 0.000 21.799 0.000 copy.py:242(_deepcopy_dict) 291636 0.504 0.000 0.686 0.000 copy.py:256(_keep_alive) 219482/3020 6.011 0.000 46.431 0.015 copy.py:272(_reconstruct) 72154 0.086 0.000 0.129 0.000 copyreg.py:87(__newobj__) 1 0.000 0.000 0.000 0.000 copyreg.py:96(_slotnames) 755 0.004 0.000 1.136 0.002 datastructures.py:13(__init__) 240224 0.073 0.000 0.073 0.000 datastructures.py:14() 361235 0.920 0.000 1.621 0.000 datastructures.py:246(__new__) 755 0.002 0.000 0.004 0.000 datastructures.py:28(__iter__) 8128/4064 0.035 0.000 0.038 0.000 deconstruct.py:16(__new__) 15847 0.033 0.000 0.089 0.000 dispatcher.py:15(_make_id) 15847 0.505 0.000 2.044 0.000 dispatcher.py:180(send) 15847 0.013 0.000 0.013 0.000 dispatcher.py:248(_clear_dead_receivers) 15847 0.519 0.000 1.066 0.000 dispatcher.py:259(_live_receivers) 37005 0.039 0.000 0.066 0.000 encoding.py:63(is_protected_type) 470101 0.514 0.000 0.767 0.000 encoding.py:72(force_text) 2 0.007 0.004 2.051 1.026 executor.py:23(migration_plan) 30 0.000 0.000 0.000 0.000 executor.py:49() 1 0.268 0.268 178.669 178.669 executor.py:65(migrate) 1 0.001 0.001 0.003 0.003 executor.py:74() 588 0.013 0.000 45.162 0.077 fields.py:110(state_forwards) 744 0.002 0.000 0.003 0.000 fields.py:25(model_name_lower) 744 0.014 0.000 56.843 0.076 fields.py:43(state_forwards) 588 0.002 0.000 0.003 0.000 fields.py:95(model_name_lower) 15847 0.051 0.000 1.608 0.000 functional.py:164(__wrapper__) 51425/37681 0.179 0.000 19.499 0.001 functional.py:32(__get__) 15847 0.089 0.000 1.557 0.000 functional.py:65(__init__) 15847 0.731 0.000 1.468 0.000 functional.py:78(__prepare_class__) 15448 0.059 0.000 0.073 0.000 functools.py:349(__init__) 28949 0.023 0.000 0.023 0.000 functools.py:353(__hash__) 15448 0.118 0.000 0.266 0.000 functools.py:356(_make_key) 15448 0.144 0.000 26.768 0.002 functools.py:440(wrapper) 21087 0.163 0.000 0.290 0.000 functools.py:515(cache_clear) 1541 0.005 0.000 0.008 0.000 functools.py:97(_gt_from_lt) 70 0.002 0.000 2.043 0.029 graph.py:139(forwards_plan) 271880 0.097 0.000 0.097 0.000 graph.py:149() 101430 0.113 0.000 0.113 0.000 graph.py:149() 1 0.002 0.002 0.004 0.004 graph.py:214(leaf_nodes) 1754 0.001 0.000 0.002 0.000 graph.py:224() 70 0.437 0.006 0.690 0.010 graph.py:229(ensure_not_cyclic) 458 0.000 0.000 0.000 0.000 graph.py:33(__eq__) 1706/853 0.002 0.000 0.004 0.000 graph.py:36(__lt__) 1045 0.000 0.000 0.000 0.000 graph.py:42(__getitem__) 1406/70 0.081 0.000 1.351 0.019 graph.py:59(ancestors) 100393 0.103 0.000 0.255 0.000 inspect.py:77(isclass) 15847 0.249 0.000 1.046 0.000 manager.py:11(ensure_default_manager) 15847 0.163 0.000 0.269 0.000 manager.py:155(contribute_to_class) 15847 0.067 0.000 0.067 0.000 manager.py:177(_set_creation_counter) 15847 0.018 0.000 0.018 0.000 manager.py:245(__init__) 15847 0.014 0.000 0.014 0.000 manager.py:248(__get__) 52852 0.036 0.000 0.036 0.000 manager.py:25() 15847 0.076 0.000 0.088 0.000 manager.py:62(__new__) 15847 0.122 0.000 0.189 0.000 manager.py:68(__init__) 3020 0.016 0.000 0.019 0.000 migration.py:67(__hash__) 755 0.015 0.000 147.159 0.195 migration.py:70(mutate_state) 165 0.001 0.000 1.343 0.008 models.py:109(state_forwards) 450 0.007 0.000 12.415 0.028 models.py:46(state_forwards) 165 0.001 0.000 0.001 0.000 models.py:95(name_lower) 37005 0.165 0.000 2.308 0.000 module_loading.py:9(import_string) 15847 0.008 0.000 0.008 0.000 operations.py:238(max_name_length) 15847 0.032 0.000 0.032 0.000 options.py:183(label_lower) 15847 1.187 0.000 4.528 0.000 options.py:210(contribute_to_class) 15847 0.028 0.000 0.028 0.000 options.py:265(_prepare) 37005 0.330 0.000 1.398 0.000 options.py:302(add_field) 37005 0.061 0.000 0.061 0.000 options.py:332(setup_pk) 8766793 3.400 0.000 3.400 0.000 options.py:378(swapped) 15847 0.135 0.000 1.273 0.000 options.py:403(fields) 37005 0.031 0.000 0.031 0.000 options.py:420() 37005 0.020 0.000 0.020 0.000 options.py:421() 37005 0.027 0.000 0.031 0.000 options.py:422() 52852 0.088 0.000 0.170 0.000 options.py:427() 31694 0.023 0.000 0.023 0.000 options.py:62(normalize_together) 1640 3.305 0.002 18.023 0.011 options.py:700(_populate_directed_relation_graph) 665887 0.771 0.000 0.840 0.000 options.py:716() 1640 0.022 0.000 18.046 0.011 options.py:735(_relation_tree) 1014841 12.526 0.000 19.157 0.000 options.py:739(_expire_cache) 22141 0.037 0.000 18.654 0.001 options.py:756(get_fields) 479603/37988 6.032 0.000 19.371 0.001 options.py:770(_get_fields) 1104488 0.612 0.000 0.612 0.000 options.py:839() 361235 1.990 0.000 3.611 0.000 options.py:84(make_immutable_fields_list) 345388 0.126 0.000 0.126 0.000 options.py:848() 15847 0.507 0.000 0.987 0.000 options.py:94(__init__) 15847 0.032 0.000 0.032 0.000 re.py:307(_compile_repl) 15847 0.053 0.000 0.085 0.000 re.py:324(_subx) 15847 0.043 0.000 0.202 0.000 re.py:330(filter) 19951 0.016 0.000 0.016 0.000 registry.py:119(check_apps_ready) 30380 0.022 0.000 0.022 0.000 registry.py:126(check_models_ready) 1511 0.005 0.000 0.010 0.000 registry.py:133(get_app_configs) 2593 0.010 0.000 0.012 0.000 registry.py:140(get_app_config) 13501 3.532 0.000 26.301 0.002 registry.py:153(get_models) 2593 0.017 0.000 0.047 0.000 registry.py:176(get_model) 1511 0.033 0.000 0.298 0.000 registry.py:20(__init__) 15847 0.794 0.000 2.396 0.000 registry.py:225(get_containing_app_config) 27616 0.206 0.000 0.248 0.000 registry.py:244(get_registered_model) 21087 1.906 0.000 27.767 0.001 registry.py:323(clear_cache) 27616 0.317 0.000 0.705 0.000 registry.py:339(lazy_model_operation) 13808 0.073 0.000 0.433 0.000 registry.py:355(function) 15847 0.112 0.000 0.711 0.000 registry.py:368(do_pending_operations) 1511 0.052 0.000 0.203 0.000 registry.py:58(populate) 1511 0.004 0.000 0.012 0.000 registry.py:95() 1511 0.001 0.000 0.001 0.000 registry.py:97() 14286 0.031 0.000 0.040 0.000 related.py:104(related_model) 13808 0.080 0.000 0.080 0.000 related.py:1284(__init__) 13640 0.015 0.000 0.015 0.000 related.py:1332(related_model) 13808 0.027 0.000 0.027 0.000 related.py:1397(is_hidden) 13808 0.060 0.000 0.140 0.000 related.py:1461(__init__) 13808 0.031 0.000 0.031 0.000 related.py:1484(set_field_name) 6439 0.024 0.000 0.087 0.000 related.py:1496(__init__) 13808 0.122 0.000 1.194 0.000 related.py:1571(__init__) 13808 0.239 0.000 34.143 0.002 related.py:1635(deconstruct) 13808 0.109 0.000 2.359 0.000 related.py:1814(contribute_to_class) 13808 0.026 0.000 0.053 0.000 related.py:1818(contribute_to_related_class) 13808 0.325 0.000 1.697 0.000 related.py:1853(__init__) 13808 0.147 0.000 34.348 0.002 related.py:1927(deconstruct) 13808 0.033 0.000 0.033 0.000 related.py:1979(get_attname) 13808 0.035 0.000 0.068 0.000 related.py:1982(get_attname_column) 13808 0.060 0.000 0.113 0.000 related.py:2017(contribute_to_related_class) 6439 0.047 0.000 0.872 0.000 related.py:2088(__init__) 6439 0.032 0.000 16.465 0.003 related.py:2092(deconstruct) 13808 0.243 0.000 2.129 0.000 related.py:278(contribute_to_class) 13808 0.044 0.000 0.273 0.000 related.py:292(resolve_related_class) 13808 7.745 0.001 32.658 0.002 related.py:297(swappable_setting) 13808 0.041 0.000 0.072 0.000 related.py:321(set_attributes_from_rel) 13808 0.044 0.000 0.229 0.000 related.py:334(do_related_class) 20247 0.050 0.000 0.059 0.000 related.py:37(resolve_relation) 13808 0.054 0.000 0.085 0.000 related.py:539(__init__) 13808 0.238 0.000 0.918 0.000 related.py:62(lazy_related_operation) 13808 0.026 0.000 0.068 0.000 related.py:77() 41424 0.051 0.000 0.267 0.000 related.py:78() 110929 0.381 0.000 0.437 0.000 signals.py:20(_resolve_references) 15847 0.124 0.000 0.159 0.000 sre_parse.py:859(expand_template) 1510 0.024 0.000 60.544 0.040 state.py:150(clone) 1510 0.623 0.000 12.556 0.008 state.py:153() 1 0.000 0.000 0.000 0.000 state.py:160(apps) 50 0.000 0.000 0.001 0.000 state.py:196(__init__) 1511 0.043 0.000 1.334 0.001 state.py:212(__init__) 1511 0.002 0.000 0.002 0.000 state.py:224() 1511 0.001 0.000 0.001 0.000 state.py:225() 7128 0.019 0.000 26.124 0.004 state.py:239(bulk_update) 812 0.005 0.000 0.008 0.000 state.py:24(_get_app_label_and_model_name) 3293 0.087 0.000 82.106 0.025 state.py:251(render_multiple) 1510 0.065 0.000 47.961 0.032 state.py:277(clone) 15847 0.227 0.000 1.504 0.000 state.py:288(register_model) 16023 0.070 0.000 0.169 0.000 state.py:297(unregister_model) 419288 5.674 0.000 8.447 0.000 state.py:316(__init__) 2141 0.109 0.000 19.108 0.009 state.py:32(get_related_models_recursive) 450 0.001 0.000 0.001 0.000 state.py:344(name_lower) 22141 0.128 0.000 18.981 0.001 state.py:43(_related_models) 22141 0.102 0.000 0.182 0.000 state.py:45() 22141 0.011 0.000 0.011 0.000 state.py:48() 52852 0.501 0.000 42.763 0.001 state.py:502(construct_fields) 15847 0.074 0.000 0.158 0.000 state.py:509(construct_managers) 418838 3.500 0.000 11.933 0.000 state.py:523(clone) 15847 1.165 0.000 68.592 0.004 state.py:534(render) 31694 0.045 0.000 0.080 0.000 state.py:543() 1511 0.003 0.000 0.003 0.000 state.py:70(__init__) 450 0.004 0.000 12.395 0.028 state.py:75(add_model) 165 0.002 0.000 1.341 0.008 state.py:81(remove_model) 1782 0.123 0.000 114.351 0.064 state.py:89(reload_model) 15847 0.063 0.000 0.743 0.000 text.py:426(camel_case_to_spaces) 15847 0.011 0.000 0.011 0.000 utils.py:178(truncate_name) 15847 0.038 0.000 0.070 0.000 utils.py:197(__getitem__) 34055 0.142 0.000 0.269 0.000 utils.py:4(make_model_tuple) 4064 0.006 0.000 0.006 0.000 validators.py:274(__init__) 110929 0.306 0.000 0.306 0.000 weakref.py:65(__call__) 469147 1.205 0.000 1.375 0.000 {built-in method __new__ of type object at 0x7fa3e030f080} 1511 0.005 0.000 0.017 0.000 {built-in method _count_elements} 37005 0.039 0.000 0.039 0.000 {built-in method acquire_lock} 75521 0.046 0.000 0.046 0.000 {built-in method allocate_lock} 16603 0.033 0.000 0.070 0.000 {built-in method any} 37005 0.096 0.000 0.176 0.000 {built-in method bisect} 8049137 6.088 0.000 6.088 0.000 {built-in method delattr} 1 0.000 0.000 179.169 179.169 {built-in method exec} 74010 0.034 0.000 0.034 0.000 {built-in method get_ident} 1679690 1.892 0.000 1.892 0.000 {built-in method getattr} 3205934 3.622 0.000 3.622 0.000 {built-in method hasattr} 18468 0.017 0.000 0.017 0.000 {built-in method hash} 4019757 1.035 0.000 1.035 0.000 {built-in method id} 2251335/2251334 1.887 0.000 2.483 0.000 {built-in method isinstance} 1057158 0.759 0.000 0.759 0.000 {built-in method issubclass} 146573 0.149 0.000 0.149 0.000 {built-in method iter} 1115563 0.304 0.000 0.304 0.000 {built-in method len} 7128 0.012 0.000 26.136 0.004 {built-in method next} 1407006 2.073 0.000 2.073 0.000 {built-in method proxy} 37005 0.021 0.000 0.021 0.000 {built-in method release_lock} 93043 0.132 0.000 0.132 0.000 {built-in method setattr} 35103 0.168 0.000 0.172 0.000 {built-in method sorted} 291636 0.151 0.000 0.151 0.000 {built-in method vars} 219482 0.722 0.000 6.468 0.000 {method '__reduce_ex__' of 'object' objects} 22141 0.007 0.000 0.007 0.000 {method '__subclasses__' of 'type' objects} 503758 0.186 0.000 0.186 0.000 {method 'add' of 'set' objects} 1041222 0.357 0.000 0.357 0.000 {method 'append' of 'list' objects} 21087 0.127 0.000 0.127 0.000 {method 'clear' of 'dict' objects} 145818 0.083 0.000 0.083 0.000 {method 'copy' of 'dict' objects} 15847 0.051 0.000 0.051 0.000 {method 'copy' of 'mappingproxy' objects} 1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects} 3386544 2.141 0.000 2.879 0.000 {method 'extend' of 'list' objects} 1336 0.004 0.000 0.004 0.000 {method 'extendleft' of 'collections.deque' objects} 7446060 2.195 0.000 2.206 0.000 {method 'get' of 'dict' objects} 1 0.000 0.000 0.000 0.000 {method 'get' of 'mappingproxy' objects} 15847 0.018 0.000 0.018 0.000 {method 'group' of '_sre.SRE_Match' objects} 37005 0.040 0.000 0.040 0.000 {method 'insert' of 'list' objects} 453324 0.154 0.000 0.154 0.000 {method 'items' of 'dict' objects} 31694 0.079 0.000 0.109 0.000 {method 'join' of 'str' objects} 31694 0.033 0.000 0.033 0.000 {method 'keys' of 'mappingproxy' objects} 115018 0.057 0.000 0.057 0.000 {method 'lower' of 'str' objects} 15847 0.055 0.000 0.055 0.000 {method 'mro' of 'type' objects} 658742 0.234 0.000 0.234 0.000 {method 'pop' of 'dict' objects} 52850 0.020 0.000 0.020 0.000 {method 'pop' of 'list' objects} 4270 0.002 0.000 0.002 0.000 {method 'pop' of 'set' objects} 49335 0.013 0.000 0.015 0.000 {method 'remove' of 'set' objects} 58163 0.103 0.000 0.103 0.000 {method 'replace' of 'str' objects} 37005 0.107 0.000 0.107 0.000 {method 'rsplit' of 'str' objects} 21059 0.049 0.000 0.049 0.000 {method 'split' of 'str' objects} 1072457 0.461 0.000 0.461 0.000 {method 'startswith' of 'str' objects} 15847 0.011 0.000 0.011 0.000 {method 'strip' of 'str' objects} 15847 0.376 0.000 0.663 0.000 {method 'sub' of '_sre.SRE_Pattern' objects} 50 0.000 0.000 0.000 0.000 {method 'title' of 'str' objects} 322928 0.364 0.000 0.522 0.000 {method 'update' of 'dict' objects} 2591 0.003 0.000 0.003 0.000 {method 'update' of 'set' objects} 3022 0.985 0.000 0.985 0.000 {method 'values' of 'dict' objects}