class MigrationAutodetector:
Take a pair of ProjectStates and compare them to see what the first would need doing to make it match the second (the second usually being the project's current state).
Note that this naturally operates on entire projects at a time, as it's likely that changes interact (for example, you can't add a ForeignKey without having a migration to add the table it depends on first). A user interface may offer single-app usage if it wishes, with the caveat that it may not always be possible.
Class Method | parse_number |
Given a migration name, try to extract a number from the beginning of it. If no number is found, return None. |
Static Method | _get_dependencies_for_foreign_key |
Undocumented |
Static Method | _resolve_dependency |
Return the resolved dependency and a boolean denoting whether or not it was swappable. |
Method | __init__ |
Undocumented |
Method | _build_migration_list |
No summary |
Method | _detect_changes |
Return a dict of migration plans which will achieve the change from from_state to to_state. The dict has app labels as keys and a list of migrations as values. |
Method | _generate_added_field |
Undocumented |
Method | _generate_altered_foo_together |
Undocumented |
Method | _generate_removed_altered_foo_together |
Undocumented |
Method | _generate_removed_field |
Undocumented |
Method | _generate_through_model_map |
Through model map generation. |
Method | _get_altered_foo_together_operations |
Undocumented |
Method | _optimize_migrations |
Undocumented |
Method | _prepare_field_lists |
Prepare field lists and a list of the fields that used through models in the old state so dependencies can be made from the through model deletion to the field that uses it. |
Method | _sort_migrations |
Reorder to make things possible. Reordering may be needed so FKs work nicely inside the same app. |
Method | _trim_to_apps |
No summary |
Method | add_operation |
Undocumented |
Method | arrange_for_graph |
Take a result from changes() and a MigrationGraph, and fix the names and dependencies of the changes so they extend the graph from the leaf nodes for each app. |
Method | changes |
Main entry point to produce a list of applicable changes. Take a graph to base names on and an optional set of apps to try and restrict to (restriction is not guaranteed) |
Method | check_dependency |
Return True if the given operation depends on the given dependency, False otherwise. |
Method | create_altered_constraints |
Undocumented |
Method | create_altered_indexes |
Undocumented |
Method | deep_deconstruct |
Recursive deconstruction for a field and its arguments. Used for full comparison for rename/alter; sometimes a single-level deconstruction will not compare correctly. |
Method | generate_added_constraints |
Undocumented |
Method | generate_added_fields |
Make AddField operations. |
Method | generate_added_indexes |
Undocumented |
Method | generate_altered_db_table |
Undocumented |
Method | generate_altered_fields |
Make AlterField operations, or possibly RemovedField/AddField if alter isn't possible. |
Method | generate_altered_index_together |
Undocumented |
Method | generate_altered_managers |
Undocumented |
Method | generate_altered_options |
Work out if any non-schema-affecting options have changed and make an operation to represent them in state changes (in case Python code in migrations needs them). |
Method | generate_altered_order_with_respect_to |
Undocumented |
Method | generate_altered_unique_together |
Undocumented |
Method | generate_created_models |
No summary |
Method | generate_created_proxies |
Make CreateModel statements for proxy models. Use the same statements as that way there's less code duplication, but for proxy models it's safe to skip all the pointless field stuff and chuck out an operation. |
Method | generate_deleted_models |
No summary |
Method | generate_deleted_proxies |
Make DeleteModel options for proxy models. |
Method | generate_removed_altered_index_together |
Undocumented |
Method | generate_removed_altered_unique_together |
Undocumented |
Method | generate_removed_constraints |
Undocumented |
Method | generate_removed_fields |
Make RemoveField operations. |
Method | generate_removed_indexes |
Undocumented |
Method | generate_renamed_fields |
Work out renamed fields. |
Method | generate_renamed_models |
Find any renamed models, generate the operations for them, and remove the old entry from the model lists. Must be run before other model-level generation. |
Method | only_relation_agnostic_fields |
Return a definition of the fields that ignores field names and what related fields actually relate to. Used for detecting renames (as the related fields change during renames). |
Method | swappable_first_key |
Place potential swappable models first in lists of created models (only real way to solve #22783). |
Instance Variable | altered_constraints |
Undocumented |
Instance Variable | altered_indexes |
Undocumented |
Instance Variable | existing_apps |
Undocumented |
Instance Variable | from_state |
Undocumented |
Instance Variable | generated_operations |
Undocumented |
Instance Variable | kept_model_keys |
Undocumented |
Instance Variable | kept_proxy_keys |
Undocumented |
Instance Variable | kept_unmanaged_keys |
Undocumented |
Instance Variable | migrations |
Undocumented |
Instance Variable | new_field_keys |
Undocumented |
Instance Variable | new_model_keys |
Undocumented |
Instance Variable | new_proxy_keys |
Undocumented |
Instance Variable | new_unmanaged_keys |
Undocumented |
Instance Variable | old_field_keys |
Undocumented |
Instance Variable | old_model_keys |
Undocumented |
Instance Variable | old_proxy_keys |
Undocumented |
Instance Variable | old_unmanaged_keys |
Undocumented |
Instance Variable | questioner |
Undocumented |
Instance Variable | renamed_fields |
Undocumented |
Instance Variable | renamed_models |
Undocumented |
Instance Variable | renamed_models_rel |
Undocumented |
Instance Variable | through_users |
Undocumented |
Instance Variable | to_state |
Undocumented |
Undocumented
Return a dict of migration plans which will achieve the change from from_state to to_state. The dict has app labels as keys and a list of migrations as values.
The resulting migrations aren't specially named, but the names do matter for dependencies inside the set.
convert_apps is the list of apps to convert to use migrations (i.e. to make initial migrations for, in the usual case)
graph is an optional argument that, if provided, can help improve dependency generation and avoid potential circular dependencies.
Find all new models (both managed and unmanaged) and make create operations for them as well as separate operations to create any foreign key or M2M relationships (these are optimized later, if possible).
Defer any model options that refer to collections of fields that might be deferred (e.g. unique_together, index_together).
Find all deleted models (managed and unmanaged) and make delete operations for them as well as separate operations to delete any foreign key or M2M relationships (these are optimized later, if possible).
Also bring forward removal of any model options that refer to collections of fields - the inverse of generate_created_models().