+
    Tj_                        ^ RI t ^ RIt^ RIHtHt ^ RIHt ^ RIHt ^ RI	H
t
 ^ RIHt ^ RIHt ^ RIHt ^ R	IHt ^ R
IHt ^ RIHt ^ RIHt ^ RIHtHtHt ^ RIHt  ! R R]! RR4      4      t ! R R4      t R# )    N)defaultdict
namedtuple)Enum)TopologicalSorter)chain)settings)models)
operations)	Migration)AlterModelOptions)MigrationOptimizer)MigrationQuestioner)COMPILED_REGEX_TYPERegexObjectresolve_relation)cached_propertyc                   V   a  ] tR t^t o  ! R R]4      t]R 4       t]R 4       tRt	V t
R# )OperationDependencyc                   .    ] tR t^t^ t^t^t^t^t^t	Rt
R# )OperationDependency.Type N)__name__
__module____qualname____firstlineno__CREATEREMOVEALTERREMOVE_ORDER_WRTALTER_FOO_TOGETHERREMOVE_INDEX_OR_CONSTRAINT__static_attributes__r       V/var/www/idalgo/venv/lib/python3.14/site-packages/django/db/migrations/autodetector.pyTyper      s#    %&"r#   r%   c                6    V P                   P                  4       # N)
model_namelowerselfs   &r$   model_name_lower$OperationDependency.model_name_lower"       $$&&r#   c                6    V P                   P                  4       # r'   )
field_namer)   r*   s   &r$   field_name_lower$OperationDependency.field_name_lower&   r.   r#   r   N)r   r   r   r   r   r%   r   r,   r1   r"   __classdictcell____classdict__s   @r$   r   r      s9     't ' ' ' ' 'r#   r   z$app_label model_name field_name typec                     a  ] tR t^+t o RtR8R ltR9R ltR tR tR:R lt	R t
R	 t]R
 4       tR8R ltR tR tR tR;R ltR tR tR tR tR tR tR tR tR tR tR tR tR tR t R t!R t"R  t#R! t$R" t%R# t&R$ t'R% t(]R& 4       t)R' t*R( t+R) t,R* t-R+ t.R, t/R- t0R. t1R/ t2R0 t3R1 t4R2 t5R3 t6R8R4 lt7R5 t8]9R6 4       t:R7t;V t<R# )<MigrationAutodetectora  
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.
Nc                    Wn         W n        T;'       g    \        4       V n        VP                   UUu0 uF  w  rEVkK	  	  uppV n        R # u uppi r'   )
from_stateto_stater   
questionerr	   existing_apps)r+   r9   r:   r;   appmodels   &&&&  r$   __init__MigrationAutodetector.__init__8   sC    $ $==(;(=4>4E4EF4Ejcc4EFFs   Ac                ~    V P                  W14      pV P                  WQV4      pV'       d   V P                  WR4      pV# )z
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)
)_detect_changesarrange_for_graph_trim_to_apps)r+   graphtrim_to_appsconvert_appsmigration_namechangess   &&&&& r$   rI   MigrationAutodetector.changes>   s>     &&|;((H((?Gr#   c           
     F  a  \        V\        4      '       d"   V Uu. uF  pS P                  V4      NK  	  up# \        V\        4      '       d3   \        ;QJ d    . V 3R lV 4       F  NK  	  5# ! V 3R lV 4       4      # \        V\        4      '       d5   VP                  4        UUu/ uF  w  r2VS P                  V4      bK  	  upp# \        V\        P                  4      '       dB   VP                  S P                  VP                  4      S P                  VP                  4      3# \        V\        4      '       d   \        V4      # \        V\        4      '       d   V# \        VR4      '       d   VP                  4       p\        V\         P"                  4      '       d
   VR,          pVw  rVpTV Uu. uF  pS P                  V4      NK  	  upVP                  4        UUu/ uF  w  r2VS P                  V4      bK  	  upp3# V# u upi u uppi u upi u uppi )z
Recursive deconstruction for a field and its arguments.
Used for full comparison for rename/alter; sometimes a single-level
deconstruction will not compare correctly.
c              3   F   <"   T F  pSP                  V4      x  K  	  R # 5ir'   )deep_deconstruct).0valuer+   s   & r$   	<genexpr>9MigrationAutodetector.deep_deconstruct.<locals>.<genexpr>S   s     G3%..u553   !deconstruct   NN)
isinstancelistrM   tupledictitems	functoolspartialfuncargskeywordsr   r   typehasattrrS   r	   Field)r+   objrO   keydeconstructedpathr^   kwargss   f&      r$   rM   &MigrationAutodetector.deep_deconstructJ   s    c4  >ABcUD))%0cBBU##5G3G5G5G3GGGT""HK		T*#C..u55TTY..//%%chh/%%cll3 
 011s##T"" JS-((OO-M#v||,, -b 1!.D;?@4%&&u-4@EK\\^T^zsd++E22^T  J= C U, ATs   H*H:H)H
c                    . p\        VP                  4       4       Fn  w  r4V P                  V4      pVP                  '       d6   VP                  P                  '       d   V^,          P                  RR4       VP                  V4       Kp  	  V# )z
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).
toN)sortedrZ   rM   remote_fieldr>   popappend)r+   fields
fields_defnamefielddeconstructions   &&    r$   only_relation_agnostic_fields3MigrationAutodetector.only_relation_agnostic_fieldsq   sx     
!&,,.1KD!2259N!!!e&8&8&>&>&>q!%%dD1n-	 2
 r#   c                   / V n         / V n        / V n        / V n        \	        4       V n        \	        4       V n        \	        4       V n        \	        4       V n        \	        4       V n	        \	        4       V n
        V P                  P                  P                  4        F  w  w  r4pVP                  P                  RR4      '       g   V P                  P!                  W434       KH  W0P                  P"                  9  g   Kd  VP                  P                  R4      '       d   V P                  P!                  W434       K  V P
                  P!                  W434       K  	  V P$                  P                  P                  4        F  w  w  r4pVP                  P                  RR4      '       g   V P                  P!                  W434       KH  W0P                  P"                  9  g   V'       g   Kl  W19   g   Kt  VP                  P                  R4      '       d   V P                  P!                  W434       K  V P                  P!                  W434       K  	  V P                  P'                  4        V P$                  P'                  4        V P)                  4        V P+                  4        V P-                  4        V P/                  4        V P1                  4        V P3                  4        V P5                  4        V P7                  4        V P9                  4        V P;                  4        V P=                  4        V P?                  4        V PA                  4        V PC                  4        V PE                  4        V PG                  4        V PI                  4        V PK                  4        V PM                  4        V PO                  4        V PQ                  4        V PS                  4        V PU                  4        V PW                  4        V PY                  4        V P[                  4        V P]                  4        V P_                  4        V Pa                  V4       V Pc                  4        V Pd                  # )a  
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.
managedTproxy)3generated_operationsaltered_indexesaltered_constraintsrenamed_fieldssetold_model_keysold_proxy_keysold_unmanaged_keysnew_model_keysnew_proxy_keysnew_unmanaged_keysr9   r	   rZ   optionsgetadd	real_appsr:   resolve_fields_and_relationsgenerate_renamed_models_prepare_field_lists_generate_through_model_mapgenerate_deleted_modelsgenerate_created_modelsgenerate_deleted_proxiesgenerate_created_proxiesgenerate_altered_optionsgenerate_altered_managers!generate_altered_db_table_commentcreate_renamed_fieldscreate_altered_indexescreate_altered_constraintsgenerate_removed_constraintsgenerate_removed_indexesgenerate_renamed_fieldsgenerate_renamed_indexes(generate_removed_altered_unique_togethergenerate_removed_fieldsgenerate_added_fieldsgenerate_altered_fields&generate_altered_order_with_respect_to generate_altered_unique_togethergenerate_added_indexesgenerate_added_constraintsgenerate_altered_constraintsgenerate_altered_db_table_sort_migrations_build_migration_list_optimize_migrations
migrations)r+   rG   rE   	app_labelr(   model_states   &&&   r$   rB   %MigrationAutodetector._detect_changes   sd   & %'!!#%   "e!e"%%!e!e"%%48OO4J4J4P4P4R0#Y[&&**9d;;''++Y,CD//";";;&&**733''++Y,CD''++Y,CD 5S 59MM4H4H4N4N4P0#Y[&&**9d;;''++Y,CD//";";;!:&&**733''++Y,CD''++Y,CD 5Q 	446224 	$$& 	!!#((* 	$$&$$&%%'%%'%%'&&(..0 	""$ 	##%'')))+%%'$$&%%'557$$&""$$$&335--/##%'')))+&&(""5)!!#r#   c                   V P                   V P                  ,          V n        V P                  V P                  ,          V n        V P                  V P                  ,          V n        / V n	        V P                   UUUu0 uFS  w  rV P                  P                  WP                  P                  W3V4      3,          P                   F  pWV3kK	  	  KU  	  upppV n        V P                   UUUu0 uF8  w  rV P                   P                  W3,          P                   F  pWV3kK	  	  K:  	  upppV n        R# u upppi u upppi )z
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.
N)r~   r   kept_model_keysr   r   kept_proxy_keysr   r   kept_unmanaged_keysthrough_usersr9   r	   renamed_modelsr   ro   old_field_keysr:   new_field_keysr+   r   r(   r0   s   &   r$   r   *MigrationAutodetector._prepare_field_lists   s*     $22T5H5HH#22T5H5HH#'#:#:T=T=T#T  *.)=)=
)=%	"oo44..22I3JJWWf
 J/ 0)=
 *.)=)=
)=%	"mm2293HIPP
 J/P 0)=


s   >AD;1>Ec                   \        V P                  4       F  w  rV P                  P                  W3V4      pV P                  P
                  W3,          pVP                  P                  4        Fj  w  rV\        VR4      '       g   K  \        VP                  RR4      '       g   K8  \        VP                  P                  W4      pVVV3V P                  V&   Kl  	  K  	  R# )zThrough model map generation.rl   throughN)rk   r~   r   r   r9   r	   ro   rZ   ra   getattrrl   r   r   r   )r+   r   r(   old_model_nameold_model_stater0   rr   through_keys   &       r$   r   1MigrationAutodetector._generate_through_model_map   s    %+D,?,?%@!I!0044'N #oo44Y5NOO%4%;%;%A%A%C!
5.11g&&	47 7 #3**22I#K "&"7D&&{3 &D &Ar#   c                    V P                   R8w  d   V R3# \        \        V P                  4      P	                  R4      w  r\        VVP                  4       V P                  V P                  4      R3# )zX
Return the resolved dependency and a boolean denoting whether or not
it was swappable.
__setting__F.T)	r   r   r   r(   splitr   r)   r0   r`   )
dependencyresolved_app_labelresolved_object_names   &  r$   _resolve_dependency)MigrationAutodetector._resolve_dependency  sy     =0u$$3:j++4

%* 	1  "$**,%%	 
 	
r#   c           
        / V n         \        R V P                  P                  4        4       4      pRpV'       Ed   \	        V P                  4       EF3  p. p\        4       p\        V P                  V,          4       EF  pRp\        4       p	VP                   EF  p
T
pV P                  V
4      w  rV
P                  V8w  g   K,  V P                  P                  V
P                  . 4       F  pV P                  W4      '       g   K  Rp M	  V'       g    EM$V'       d*   V	P                  VP                  VP                  34       K  V
P                  V P                   9   dM   V	P                  V
P                  V P                   V
P                  ,          R,          P                  34       EK  V'       d~   V'       dV   VP                  V
P                  4      '       d5   V	P                  VP                  V
P                  4      ^ ,          4       EK|  V	P                  V
P                  R34       EK  RpEK  	  V'       d:   VP!                  V4       VP#                  V	4       V P                  V,          ^  EK    M	  V'       g   V'       g   EKC  V P                  V,          '       d	   V'       d   \%        R\&        3R. R. /4      pV! R\)        V P                   P                  V. 4      4      ^,           ,          V4      p\        V4      Vn        W_n        W@P.                  9  Vn        V P                   P3                  V. 4      P!                  V4       RpEK  WPP                  V,          ,           V P                  V&   EK6  	  \        R	 V P                  P                  4        4       4      pVV8X  d(   V'       g   RpM\5        R
V P                  ,          4      hTpEK  R# )a  
Chop the lists of operations up into migrations with dependencies on
each other. Do this by going through an app's list of operations until
one is found that has an outgoing dependency that isn't in another
app's migration yet (hasn't been chopped off its list). Then chop off
the operations before it into a migration and move onto the next app.
If the loops completes without doing anything, there's a circular
dependency (which _should_ be impossible as the operations are
all split at this point so they can't depend and be depended on).
c              3   8   "   T F  p\        V4      x  K  	  R # 5ir'   lenrN   xs   & r$   rP   >MigrationAutodetector._build_migration_list.<locals>.<genexpr>5  s     I&Hc!ff&H   FT	__first__r   r
   dependencieszauto_%ic              3   8   "   T F  p\        V4      x  K  	  R # 5ir'   r   r   s   & r$   rP   r     s     Q.Pc!ff.Pr   z)Cannot resolve operation dependencies: %rN)r   sumry   valuesrk   r}   rW   
_auto_depsr   r   r   check_dependencyr   r(   rq   
leaf_nodesrn   updater`   r   r   r   r
   r<   initial
setdefault
ValueError)r+   rE   num_ops	chop_moder   choppedr   	operationdeps_satisfiedoperation_dependenciesdeporiginal_depis_swappable_depother_operationsubclassinstancenew_num_opss   &&               r$   r   +MigrationAutodetector._build_migration_list)  sG    Id&?&?&F&F&HII	g $D$=$=>	"u!%d&?&?	&J!KI%)N-0U*(33
 (+040H0H0M-==I5 483L3L3P3P #r4 $(#8#8#N#N5:N$)4 $2 %#3$:$>$>,8,B,B,8,C,C)*%& &)]]doo%E$:$>$>,/MM,0OOCMM,J2,N,S,S)*%& (1 ,1U5E5Ecmm5T5T,B,F,F050@0@0OPQ0R-. -C,F,F140L-. :?m  4n &y1$++,BC 55i@C "LB  7744Y??9#''&L)2~rB$
 $,%T__-@-@B-O)PST)TU%$ 15\0B-.5++4<N<N+N(229bAHHR$)	 $&?&?	&JJ 11)<k ?p Qd.G.G.N.N.PQQKg%  $I$C334  "GQ r#   c                  a a \        S P                  P                  4       4       F  w  r\        4       pV Fq  pVP	                  V4       VP
                   FM  oS P                  S4      ^ ,          oSP                  V8w  d   K.  VP                  ! V.VV 3R lV 4       O5!   KO  	  Ks  	  \        VP                  4       4      S P                  V&   K  	  R# )zc
Reorder to make things possible. Reordering may be needed so FKs work
nicely inside the same app.
c              3   \   <"   T F!  pSP                  VS4      '       g   K  Vx  K#  	  R # 5ir'   )r   )rN   r   r   r+   s   & r$   rP   9MigrationAutodetector._sort_migrations.<locals>.<genexpr>  s"      QCq43H3HC3PCs   ,
,N)
rk   ry   rZ   r   r   r   r   r   rW   static_order)r+   r   opstsopr   s   f    @r$   r   &MigrationAutodetector._sort_migrations  s    
 %T%>%>%D%D%FGNI"$Br
==C 2237:C}}	1 FF2R QC QR )  488I3JD%%i0 Hr#   c                   V P                   P                  4        FF  w  r\        W"R ,          4       F+  w  r4VP                  P	                  WP
                  34       K-  	  KH  	  V P                   P                  4        F/  pV F&  p\        \        VP                  4      4      Vn        K(  	  K1  	  V P                   P                  4        F7  w  rV F,  p\        4       P                  VP                  V4      Vn        K.  	  K9  	  R# )rT   N)r   rZ   zipr   rn   rq   r   rW   r}   r   optimizer
   )r+   r   r   m1m2	migrations   &     r$   r   *MigrationAutodetector._optimize_migrations  s    %)__%:%:%<!IjR.9&&	77';< : &=
 //002J'	)-c)2H2H.I)J	& ( 3
 &*__%:%:%<!I'	'9';'D'D(()(	$ ( &=r#   c                	  a SP                   fe   SP                  \        P                  P                  8X  d<   \        V\        P                  4      ;'       d    VP                  SP                  8H  # SP                   Ee   SP                  \        P                  P                  8X  d   \        V\        P                  4      ;'       dx    VP                  SP                  8H  ;'       dW    \        ;QJ d)    V3R lVP                   4       F  '       g   K   RM	  RM! V3R lVP                   4       4      ;'       g]    \        V\        P                  4      ;'       d;    VP                  SP                  8H  ;'       d    VP                  SP                  8H  # SP                   e   SP                  \        P                  P                  8X  d]   \        V\        P                  4      ;'       d;    VP                  SP                  8H  ;'       d    VP                  SP                  8H  # SP                   fe   SP                  \        P                  P                  8X  d<   \        V\        P                   4      ;'       d    VP                  SP                  8H  # SP                   e   SP                  \        P                  P"                  8X  d]   \        V\        P$                  4      ;'       d;    VP                  SP                  8H  ;'       d    VP                  SP                  8H  # SP                   e   SP                  \        P                  P&                  8X  du   \        V\        P(                  4      ;'       dS    VP                  SP                  8H  ;'       d2    VP*                  ;'       g    RP-                  4       SP                  8g  # SP                   eu   SP                  \        P                  P.                  8X  dL   \        V\        P0                  \        P2                  34      ;'       d    VP                  SP                  8H  # SP                   eu   SP                  \        P                  P4                  8X  dL   \        V\        P6                  \        P8                  34      ;'       d    VP                  SP                  8H  # \;        RS: 24      h)zV
Return True if the given operation depends on the given dependency,
False otherwise.
c              3   F   <"   T F  w  rSP                   V8H  x  K  	  R # 5ir'   )r0   )rN   r   yr   s   &  r$   rP   9MigrationAutodetector.check_dependency.<locals>.<genexpr>  s      P?Otq
--2?OrR   TF zCan't handle dependency )r0   r`   r   r%   r   rV   r
   CreateModel
name_lowerr,   anyro   AddFieldr1   r   RemoveFieldDeleteModelr   
AlterFieldr   AlterOrderWithRespectToorder_with_respect_tor)   r    AlterUniqueTogetherAlterIndexTogetherr!   RemoveIndexRemoveConstraintr   )r+   r   r   s   &&fr$   r   &MigrationAutodetector.check_dependency  s'    !!)#6#;#;#B#BB 9j&<&<= H H((J,G,GG !!-#6#;#;#B#BB 9j&<&<= Q Q((J,G,GGQ QCPy?O?OPCCCPy?O?OPP 
 9j&9&9: H H..*2M2MMH H((J,G,GG !!-#6#;#;#B#BB 9j&<&<= H H..*2M2MMH H((J,G,GG !!)#6#;#;#B#BB 9j&<&<= H H((J,G,GG !!-#6#;#;#A#AA 9j&;&;< H H..*2M2MMH H((J,G,GG !!-#6#;#;#L#LL 9j&H&HI / /((J,G,GG/ /44::AAC../ !!-#6#;#;#N#NN 33Z5R5RS H H ((J,G,GG !!-#6#;#;#V#VV ++Z-H-HI N N ..*2M2MM ZIJJr#   c                    T;'       g    . Vn         V'       d/   V P                  P                  V. 4      P                  ^ V4       R# V P                  P                  V. 4      P	                  V4       R# )r   N)r   ry   r   insertrn   )r+   r   r   r   	beginnings   &&&&&r$   add_operation#MigrationAutodetector.add_operation%  s[      ,11r	%%00B?FFq)T%%00B?FFyQr#   c                    V P                   P                  V,          pVP                   Uu0 uF'  p\        V\        4      '       d   TMVP
                  kK)  	  ppV^ ,          : RV^,          : 2pVP                  P                  R4      '       g@   RV9   g9   RV9   g2   \        P                  P                  4       VP                  4       8X  d!   RV^ ,          ,           RV^,          ,           3#  V# u upi   \         d     T# i ; i)zd
Place potential swappable models first in lists of created models (only
real way to solve #22783).
r   	swappableAbstractUserAbstractBaseUser___)r:   r	   basesrV   strr   r   r   r   AUTH_USER_MODELr)   LookupError)r+   itemr   base
base_namesstring_versions   &&    r$   swappable_first_key)MigrationAutodetector.swappable_first_key.  s    
	--..t4K (---D #4--4==@-   )-Qa9N##''44!Z/%3++113~7K7K7MMQa99 N
   		s#   +C; -C6BC; 6C; ;D
	D
c                r   / V n         / V n        V P                  V P                  ,
          p\	        V4       EFu  w  r#V P
                  P                  W#3,          pV P                  VP                  4      pV P                  V P                  ,
          pV EF  w  rxWr8X  g   K  V P                  P                  Wx3,          p	V P                  V	P                  4      p
WZ8X  g   KO  V P                  P                  W4      '       g   Kr  . p\        VP                  P                  4       4      V P
                  P                  W#3,          P                  4        UUu. uF&  pVP                  4        F  pVP                  NK  	  K(  	  upp,           pV FD  pVP                   '       g   K  VP#                  V P%                  VVVV P
                  4      4       KF  	  V P'                  V\(        P*                  ! V	P,                  VP,                  R7      VR7       WP                   W#3&   V	P.                  : RV	P0                  : 2pVP.                  : RVP0                  : 2V P                  V&   V P                  P3                  Wx34       V P                  P5                  W#34        EKs  	  EKx  	  R# u uppi )z
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.
)old_namenew_namer   r   N)r   renamed_models_relr   r~   rk   r:   r	   rt   ro   r9   r;   ask_rename_modelrW   r   	relationsrl   is_relationextend!_get_dependencies_for_foreign_keyr  r
   RenameModelrq   r   r   remover   )r+   added_modelsr   r(   r   model_fields_defremoved_modelsrem_app_labelrem_model_namerem_model_staterem_model_fields_defr   r$  rr   ro   renamed_models_rel_keys   &               r$   r   -MigrationAutodetector.generate_renamed_modelsE  s    !"$**T-@-@@%+L%9!I--..y/DEK#AA+BTBTU!0043F3FFN1?- -&*oo&<&<%5'O ,0+M+M'..,( (???;;+  ,.L%)+*<*<*C*C*E%F151H1H$-$92""(&(2+J2+I .7-=-=-?E	 !& 2 2 .@	 !32+J &F *0#(#4#4#4$0$7$7(,(N(N,5,6,1,0MM	)*%& *0 !.. ) * 6 6-<-A-A-8-=-=!" .: /  JX//	0EF / 9 9 / : :62 %0$9$9$/$:$:!" !334JK !//667VW //33Y4KL!i 2@ &:$Js   ,J3c                   V P                   V P                  ,          pV P                  V,
          pV P                  V,
          p\	        \        W P                  RR7      \        W0P                  RR7      4      pV EF  w  rVV P                  P                  WV3,          p/ pRp	VP                  P                  4        F  w  rVP                  '       g   K  VP                  P                  '       dJ   VP                  '       d   VP                  P                  p	M VP                  P                  '       g   WV
&   \        VP                  RR4      '       g   K  WV
&   K  	  VP                   P#                  R4      pVP                   P#                  R4      pVP                   P#                  RR4      pVP                   P#                  RR4      p\%        WVR\$        P&                  P(                  4      .pVP*                   EFV  p\-        V\.        4      '       g   K  R	V9   g   K%  VP1                  R	^4      w  ppVP3                  \%        VVR\$        P&                  P4                  4      4       V P6                  P                  P9                  VV34      pV P                  P                  P9                  VV34      pV'       g   K  V'       g   K  \;        VP                  4      P=                  VP                  4      P?                  VP                  4      pV F8  pVP3                  \%        VVV\$        P&                  P(                  4      4       K:  	  EKY  	  V	'       dB   VP3                  \%        . \A        WV4      ORN\$        P&                  P4                  N5!  4       T PC                  T\D        PF                  ! VPH                  VP                  P                  4        Uu. uF  pV^ ,          V9  g   K  VNK  	  upVP                   VP*                  VPJ                  R
7      VRR7       VP                   P9                  RR4      '       g   EK  \        VP                  4       4       F  w  ppV PM                  VVVV P                  4      pVP3                  \%        WVR\$        P&                  P4                  4      4       V PC                  V\D        PN                  ! VVVR7      \Q        \;        V4      4      R7       K  	  V'       dt   V PC                  V\D        PR                  ! VVR7      \%        VVV\$        P&                  P4                  4      \%        WVR\$        P&                  P4                  4      .R7       \        V4       Uu. uF(  p\%        WVV\$        P&                  P4                  4      NK*  	  ppVP3                  \%        WVR\$        P&                  P4                  4      4       V F-  pV PC                  V\D        PT                  ! VVR7      VR7       K/  	  V F-  pV PC                  V\D        PV                  ! VVR7      VR7       K/  	  V'       d+   V PC                  V\D        PX                  ! VVR7      VR7       V P                  PZ                  pWV3V P\                  9   g   EK?  VWV3,          P                  4        F  w  ppV P                  P                  V,          pVP                  4        Fj  w  p p!V PC                  VP^                  \D        P`                  ! VPH                  V V!R7      \%        VVR\$        P&                  P4                  4      .R7       Kl  	  K  	  EK  	  R# u upi u upi )a:  
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).
T)rd   reverseNr   indexesconstraintsunique_togetherr  r   rq   ro   r   r  managers)r   r  rw   r(   rq   rr   r!  rq   r  r(   indexr(   
constraintrq   r7  )1r~   r   r   r   r   rk   r  r:   r	   ro   rZ   rl   r>   primary_keyparent_linkr   r   rm   r   r%   r   r  rV   r  r   rn   r   r9   r   r}   
differenceintersectionr   r  r
   r   rq   r9  r'  r   rW   r  AddIndexAddConstraintr  r$  r   r   r  )"r+   old_keysr*  added_unmanaged_modelsall_added_modelsr   r(   r   related_fieldsprimary_key_relr0   rr   r5  r6  r7  r  r   r  base_app_label	base_nameold_base_model_statenew_base_model_stateremoved_base_fieldsremoved_base_fielddrq   related_dependenciesr=  r?  r$  related_model_keyrelated_model_staterelated_field_namerelated_fields"   &                                 r$   r   -MigrationAutodetector.generate_created_models  s    &&)@)@@**X5!%!8!88!C <%=%=tL)/G/GQUV
 &6!I--..y/DEKN"O%0%7%7%=%=%?!
%%%))/// ,,,.3.@.@.F.FO!&!3!3!?!?!?9>:6u119dCC5:z2 &@ "))--i8G%--11-@K)11556GNO$/$7$7$;$;'%!
 $41D1I1I1P1PL $))dC((SD[04

30B-NI ''+*% /44;;	 ,0??+A+A+E+E'3,( ,0==+?+?+C+C'3,( ,+0D0D 4 ; ;<'Z 4 ; ; *\+*<*<= , 3F.(// 3$2$-$6$7$<$<$C$C	!" 3F7 *J ##' )/jQ ,0077 &&$)) "-!3!3!9!9!;!;AQ4~5 !;
 (//%++(11
 *  & &&**9d;;  &n&:&:&<=e#EEMM	  ##'!t5H5M5M5T5T ""''#-!#
 "&c,&7!8 #   >0 %""66'.C
 ,%&1/44;;	 ,%49L9Q9Q9X9X
" # , #>2	$ 3D $41D1I1I1P1P 3	 ! $ !''#41D1I1I1P1P
 !""''#-# "6 #  ! *
"",,#-#- "6 #  * ""22'(7 "6 #  //I&$*=*==9B):%':5%~ +/--*>*>?P*Q'=K=Q=Q=S9*M**/99&11+>+C+C%7&3 !4$-$.$($7$<$<$C$C	!"* +  >T	:o &6^|$s   *]??]?.^c                   V P                   V P                  ,
          p\        V4       EF?  w  r#V P                  P                  W#3,          pVP
                  P                  R4      '       g   Q h\        W#R\        P                  P                  4      .pVP                   Fm  p\        V\        4      '       g   K  RV9   g   K$  VP                  R^4      w  rxVP                  \        VVR\        P                  P                  4      4       Ko  	  V P!                  V\"        P$                  ! VP&                  . VP
                  VP                  VP(                  R7      VR7       EKB  	  R# )z
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.
rx   Nr   r8  r!  )r   r   rk   r:   r	   r   r   r   r%   r   r  rV   r  r   rn   r   r  r
   r   rq   r9  )	r+   addedr   r(   r   r   r  rL  rM  s	   &        r$   r   .MigrationAutodetector.generate_created_proxiesg  s<    ##d&9&99%+E]!I--..y/DEK&&**73333 $41D1I1I1P1PL $))dC((SD[04

30B-N ''+*% /44;;	 * &&$))'//%++(11 *  - &3r#   c                p   V P                   V P                  ,          pV P                  V,
          pV P                  V,
          p\	        \        V4      \        V4      4      pV EF  w  rVV P                  P                  WV3,          p/ pVP                  P                  4        F\  w  rV
P                  '       g   K  V
P                  P                  '       d   WV	&   \        V
P                  RR4      '       g   KX  WV	&   K^  	  VP                  P                  RR4      pV'       d)   V P                  V\         P"                  ! VRR7      4       VP                  P                  RR4      ;p'       d<   V F5  pV P                  V\         P$                  ! VVP&                  R7      4       K7  	  VP                  P                  RR4      ;p'       d<   V F5  pV P                  V\         P(                  ! VVP&                  R7      4       K7  	  \        V4       FR  pV P                  V\         P*                  ! VVR7      \-        VVV\,        P.                  P0                  4      .R7       KT  	  . pV P                  P2                  pVWV3,          P                  4        F  w  w  pppVP                  4        F  w  rVP5                  \-        VVV	\,        P.                  P6                  4      4       V
P8                  '       d   KN  VP5                  \-        VVV	\,        P.                  P:                  4      4       K  	  K  	  \        V4       F7  pVP5                  \-        WVV\,        P.                  P6                  4      4       K9  	  V P<                  P?                  WWP@                  34      pV'       d6   VP5                  \-        . VO\,        P.                  P6                  N5!  4       V P                  V\         PB                  ! VP&                  R	7      \E        \G        V4      4      R7       EK  	  R# )
aN  
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().
r   Nr7  r@  r5  r(   rq   r6  r!  rq   )$r   r   r~   r   r   rk   r9   r	   ro   rZ   rl   r>   r   r   rm   r  r
   r  r  rq   r  r   r   r%   r!   r$  rn   r   many_to_manyr   r   r   r   r  rW   r}   )r+   new_keysdeleted_modelsdeleted_unmanaged_modelsall_deleted_modelsr   r(   r   rJ  r0   rr   r7  r5  r=  r6  r?  rq   r   r$  related_object_app_labelobject_namerelation_related_fieldsthrough_users   &                      r$   r   -MigrationAutodetector.generate_deleted_models  s    &&)@)@@,,x7#'#:#:X#E ">"F+C$D
 &8!I//001FGKN%0%7%7%=%=%?!
%%%))///5:z2u119dCC5:z2 &@ *11556GNO""22'(, &--11)TBBwB$E&&!"..'1!& % *1155mTJJ{J"-J&&!"33'1!+ #. ~.""**#-!
 ,%& /44OO	" #  /( L11I +4I4I*J*P*P*R' (&)@)F)F)H%J ''+4'&/44;;	 !---$++/ 8 + * 3 8 8 > >	 *I +S( ~.##'!t5H5M5M5T5T /  --119>T>T2UVL##'WW7J7O7O7V7VW &&$)) "#l"34  C &8r#   c                L   V P                   V P                  ,
          p\        V4       Fw  w  r#V P                  P                  W#3,          pVP
                  P                  R4      '       g   Q hV P                  V\        P                  ! VP                  R7      4       Ky  	  R# )z*Make DeleteModel options for proxy models.rx   r^  N)r   r   rk   r9   r	   r   r   r  r
   r  rq   )r+   deletedr   r(   r   s   &    r$   r   .MigrationAutodetector.generate_deleted_proxies  s    %%(;(;;%+G_!I//001FGK&&**73333&&$)) &5r#   c                   . V n         V P                  P                  4       p\        V P                  V,
          4       EFF  w  r#pV P
                  P                  W#3V4      pV P                  P                  W%3,          pV P                  P                  W#3,          pVP                  V4      pV P                  V4      p	\        WP                  ,
          4       EF  w  rpW8X  g   K  W8X  g   K  VP                  V4      pV P                  V4      pVP                  '       dh   VP                  P                  '       dL   RV^,          9   d>   V^,          R,          pWP                  9   d   V P                  V,          V^,          R&   VP                  V4       VP!                  4       ^,          pW8X  g;   VR,          V	R,          8X  g   K  \#        V^,          VR7      V	^,          8X  g   EK  V P$                  P'                  W<WH4      '       g   EK?  V P                   P)                  V
VVP*                  VVVVV34       VP-                  WV34       VP/                  W#V34       VV P0                  W#V3&    EKD  	  EKI  	  R# )zWork out renamed fields.rj   :r      N)	db_columnN)renamed_operationsr   copyrk   r   r   r   r9   r	   r:   	get_fieldrM   rl   r>   r"  set_attributes_from_nameget_attname_columnrY   r;   
ask_renamern   rn  r)  r   r|   )r+   r   r   r(   r0   r   r   new_model_staterr   	field_decr-  r.  rem_field_name	old_fieldold_field_dec
old_rel_toold_db_columns   &                r$   r   +MigrationAutodetector.create_renamed_fields  sV   "$,,11317.02
-I: "0044'N #oo44Y5NOO"mm2293HIO#--j9E--e4IAG!4!44B=~ !-.2N / 9 9. II$($9$9)$DM***!..444 M!$44%21%5d%;
%)@)@@595L5LZ5XM!,T266~F$-$@$@$B1$EM$1 &c*in< q!1]K$Q<(  ??55&
  !33::$1$2$-$7$7$2$-$.$)$.	!" +11!. O +..	z/RS . !//	z0QR "[B2
r#   c           
        V P                    F  w  ppppppppW7P                  8w  d@   VP                  4       p	WIn        V P	                  V\
        P                  ! VVV	R7      4       V P	                  V\
        P                  ! VVVR7      4       V P                  P                  WV34       V P                  P                  WVV34       K  	  R# )z Generate RenameField operations.r:  )r(   r  r   N)ro  rn  clonerq   r  r
   r  RenameFieldr   r)  r   )
r+   r-  r.  rem_db_columnrw  r   r(   rr   r0   altered_fields
   &         r$   r   -MigrationAutodetector.generate_renamed_fieldsV  s     $$	

 / %%3"""))#-++ &&)+' &&~'VW##YJ$GH1 %r#   c                    \        V P                  V P                  ,
          4       F  w  rpV P                  WV4       K  	  R# )zMake AddField operations.N)rk   r   r   _generate_added_fieldr   s   &   r$   r   +MigrationAutodetector.generate_added_fields{  s<    17$"5"552
-I: &&yjI2
r#   c           
        V P                   P                  W3,          P                  V4      p\        WV\        P                  P
                  4      .pVP                  '       dJ   VP                  P                  '       d.   VP                  V P                  VVVV P                   4      4       VP                  '       d!   VP                  V P                  V4      4       \        P                  \        P                  \        P                  3p\        P                  \        P                   \        P"                  3pVP$                  ;'       g    VP'                  4       ;'       g    VP)                  4       ;'       go    VP*                  ;'       g[    VP,                  ;'       d    VP.                  ;'       g3    \1        WF4      ;'       d    VP2                  ;'       g    \1        WG4      pV'       gu   VP5                  4       p\1        WF4      '       d4   VP6                  '       d"   V P8                  P;                  W24      Vn        M V P8                  P?                  W24      Vn        VP@                  '       dM   VP'                  4       '       d7   \C        VP<                  4      '       d   V P8                  PE                  W24       V PG                  V\H        PJ                  ! VVVVR 7      VR7       R# )r(   rq   rr   preserve_defaultr!  N)&r:   r	   rq  r   r%   r   rl   r>   r&  r'  	generated%_get_dependencies_for_generated_field	DateFieldDateTimeField	TimeField	AutoFieldSmallAutoFieldBigAutoFieldnullhas_defaulthas_db_defaultr_  blankempty_strings_allowedrV   auto_nowr~  auto_now_addr;   ask_auto_now_add_additiondefaultask_not_null_additionuniquecallable$ask_unique_callable_default_additionr  r
   r   )	r+   r   r(   r0   rr   r   time_fieldsauto_fieldsr  s	   &&&&     r$   r  +MigrationAutodetector._generate_added_field  s`   $$Y%:;EEjQ  z3F3K3K3R3R
 %"4"4":":":66MM	 ??? J J5 QR '')=)=v?O?OP'')>)>@S@STJJ 0 0  "0 0##%0 0 !!0 0 ;; ; ;	0 0
 5.AA5>>0 0 5. 	  KKME%--%2D2D2D $ I I! !% E E! <<<E--//HU]]4K4KOO@@X%!1	 & 	 		
r#   c                    \        V P                  V P                  ,
          4       F  w  rpV P                  WV4       K  	  R# )zMake RemoveField operations.N)rk   r   r   _generate_removed_fieldr   s   &   r$   r   -MigrationAutodetector.generate_removed_fields  s<    17$"5"552
-I: ((
K2
r#   c                \   V P                  V\        P                  ! VVR 7      \        VVV\        P                  P
                  4      \        VVV\        P                  P                  4      \        VVV\        P                  P                  4      .V P                  WV4      OR7       R# )r]  r!  N)	r  r
   r   r   r%   r   r    r!   3_get_generated_field_dependencies_for_removed_fieldr   s   &&&&r$   r  -MigrationAutodetector._generate_removed_field  s    ""% $',,==	 $',,??	 $',,GG	& II:' 	  	
r#   c                	   \        V P                  V P                  ,          4       EF  w  rpV P                  P	                  W3V4      pV P
                  P	                  WV3V4      pV P                  P                  W3,          P                  V4      pV P                  P                  W3,          P                  V4      p. p\        VR4      '       Ed    \        VP                  RR4      '       Ed   \        VP                  P                  W4      p	WP                  9   d&   VP                  P                  VP                  n        \        VP                  RR4      p
V
'       db   . V	OV
N5pWP
                  9   dK   VP                  P                  VP                  n        VP                  P                  VP                  n        \        VRR4      pV'       d   W3p\!        V Uu. uF$  pV P
                  P	                  . VOVN5V4      NK&  	  up4      Vn        \!        VP$                   Uu. uF$  pV P
                  P	                  . V	OVN5V4      NK&  	  up4      Vn        \        VRR4      ;p'       d+   \!        V4      Vn        \!        VP$                  4      Vn        VP'                  V P)                  VVVV P                  4      4       \        VR4      '       ds   \        VP                  RR4      '       dV   \        VP                  P*                  W4      p	WP                  9   d&   VP                  P*                  VP                  n        V P-                  V4      pV P-                  V4      pVV8w  g   EK`  WS8X  g   EKi  VP.                  ;'       d    VP.                  pVP.                  '       * ;'       d    VP.                  '       * pV'       g	   V'       d   RpVP0                  '       d   VP0                  '       g   VP3                  4       '       gr   VP5                  4       '       g\   VP.                  '       gJ   VP7                  4       pV P8                  P;                  W24      pV\        P<                  Jd
   VVn        RpMTpV PA                  V\B        PD                  ! VVVVR	7      VR
7       EK  V PG                  WV4       V PI                  WV4       EK  	  R# u upi u upi )zX
Make AlterField operations, or possibly RemovedField/AddField if alter
isn't possible.
rl   r>   Nr0   from_fieldsr   TFr  r!  )%rk   r   r   r   r   r|   r9   r	   rq  r:   ra   r   rl   r   r>   r0   rX   r  	to_fieldsr&  r'  r   rM   r_  r  r  r  r~  r;   ask_not_null_alterationNOT_PROVIDEDr  r  r
   r  r  r  )r+   r   r(   r0   r   old_field_namerx  	new_fieldr   
rename_keyremote_field_nameto_field_rename_keyr  from_rename_key
from_fieldto_fieldold_from_fieldsry  new_field_decboth_m2mneither_m2mr  rr   new_defaults   &                       r$   r   -MigrationAutodetector.generate_altered_fields  s   
 28$"5"552
-I: "0044'N "0044
3ZN ..y/HISSI ,,Y-BCMMI L y.11g&&7 7 .**00)
 !4!443<3I3I3O3OI**0$+I,B,BLRV$W!$*JJ*J8I*J'*.A.AA 8A7M7M7S7S	..4%22== "..9
 &iE'0&=O,1
 /:	 /:
 !//33 >/ >: >
 /:	-I) +0 -6,?,?,? !//334Kj4K(4KXV,?+I' +2)]D*QQQ05o0F	-.3I4G4G.H	+##::!"!	 y.11g&&	47 7 .**22I
 !4!445>5K5K5S5SI**2 11)<M 11)<M -.2N$11LLi6L6L"+"8"88WWAWAW=W{'+$! ) ) 5 5 7 7 ) 8 8 : : ) 6 6 6 ) 1&*oo&M&M&' 'f.A.AA,7EM/4, )&&!"--'1!+"'-=	 &2 ' 	 00
S..yjQk2
Zs   ,*S3
5*S8
c           
        \         P                  P                  p\        \        4      V n        \        V P                  4       EF  w  r#V P                  P                  W#3V4      pV P                  P                  W$3,          pV P                  P                  W#3,          pVP                  V,          pVP                  V,          pV U	u. uF  qV9  g   K  V	NK  	  p
p	V U	u. uF  qV9  g   K  V	NK  	  pp	. p. p. pV
 F  pVP                  4       pV^,          P                  R4      pV Fs  pVP                  4       pV^,          P                  R4      pVV8X  g   K4  VV8w  g   K=  VP!                  VVR34       VP!                  V4       VP!                  V4       Ku  	  K  	  V P#                  \         P$                  P                  4       EF  w  pppppVV8w  g   VV8w  d   K  VP'                  V4      pV F  p. pV
 Fb  pVP                  4       w  pppV'       d   K!  VP(                  \	        V4      8X  g   K=  \+        V4      RR08X  g   KQ  VP!                  V4       Kd  	  \-        V4      ^8X  g   K  V^ ,          p VP!                  V 4       VP!                  RV P.                  V34       V P
                  VV3,          P!                  V4       K  	  EK  	  V
 U	u. uF  qV9  g   K  V	NK  	  p
p	V U	u. uF  qV9  g   K  V	NK  	  pp	V P0                  P3                  W#3RV
RVRV//4       EK  	  R# u up	i u up	i u up	i u up	i )rm  rq   Nro   added_indexesremoved_indexesrenamed_indexes)r
   rE  option_namer   rW   renamed_index_together_valuesrk   r   r   r   r9   r	   r:   r   rS   rm   rn   $_get_altered_foo_together_operationsr  rC  ro   r}   r   rq   rz   r   )!r+   r  r   r(   r   r   ru  old_indexesnew_indexesidxr  r  r  remove_from_addedremove_from_removed	new_indexnew_index_decnew_index_name	old_indexold_index_decold_index_name	old_value	new_valueindex_together_app_labelindex_together_model_namer   removed_valuesremoved_index_togetherrenamed_index_together_indexes_r^   rg   renamed_indexs!   &                                r$   r   ,MigrationAutodetector.create_altered_indexes`  sV    ))55-8->*%+D,@,@%A!I!0044'N #oo44Y5NOO"mm2293HIO)11+>K)11+>K,7RKSk;QSSKMR.9Tks=SsskOT O ""$*	 ) 5 5 7!.q!1!5!5f!=!0I$-$9$9$;M%21%5%9%9&%AN &6*n<'..PT/UV)00;+229= "1 +* ::--99()
 !99!%>>!*!5!5i!@.<*572%2	*3*?*?*A4 !% ) 0 0D9O4P P #F/A A:AA)L &3 9:a?(Fq(I)00?'..!=#5#57MN ::46OO &!78) /=B  -,;L0L}    /.=P2P     ''+')?)?.W &B STts0   MM&M3M)M6MMMc           
         V P                   P                  4        FS  w  w  rpV P                  W4      pVR ,           F-  pV P                  V\        P
                  ! VVR7      VR7       K/  	  KU  	  R# )r  r<  r!  N)rz   rZ   _get_dependencies_for_modelr  r
   rE  )r+   r   r(   alt_indexesr   r=  s   &     r$   r   ,MigrationAutodetector.generate_added_indexes  su    484H4H4N4N4P0#Y[;;IRL$_55""''#-# ". #  6 5Qr#   c           
         V P                   P                  4        FJ  w  w  rpVR ,           F5  pV P                  V\        P                  ! VVP
                  R7      4       K7  	  KL  	  R# )r  r]  N)rz   rZ   r  r
   r  rq   )r+   r   r(   r  r=  s   &    r$   r   .MigrationAutodetector.generate_removed_indexes  s`    484H4H4N4N4P0#Y[$%677""**#-"ZZ 8 5Qr#   c                    V P                   P                  4        FE  w  w  rpVR ,           F0  w  rEpV P                  V\        P                  ! VVVVR7      4       K2  	  KG  	  R# )r  )r(   r   r  
old_fieldsN)rz   rZ   r  r
   RenameIndex)r+   r   r(   r  r  r  r  s   &      r$   r   .MigrationAutodetector.generate_renamed_indexes  sm    484H4H4N4N4P0#Y[>I!? ?:
 ""**#-!/!/#-	? 5Qr#   c           	     &   VP                  4       w  r4pVP                  4       w  rgpVP                   F  p	VP                  V	R 4       K  	  VP                   F  p	VP                  V	R 4       K  	  V P                   Fw  w  p
p
ppp
p
ppVP                  '       g   K   WP                  8X  g   K2  VR,          p VP                  V4      p\        TR T T3,           TT^,           R  ,           4      TR&   Ky  	  W4V3WgV38g  #   \         d     K  i ; i)Nro   )rS   non_db_attrsrm   ro  rn  r=  r   rX   )r+   old_constraintnew_constraintold_pathold_args
old_kwargsnew_pathnew_args
new_kwargsattrr  r  rw  rr   r0   
new_fieldsnew_field_idxs   &&&              r$   +_constraint_should_be_dropped_and_recreatedAMigrationAutodetector._constraint_should_be_dropped_and_recreated  s*    *8)C)C)E&J)7)C)C)E&J"//DNN4& 0"//DNN4& 0 $$	
=OO#C'1
$.$4$4Z$@M (-~.%'( !2!456(
8$ % J/H
3SSS " s   9DDDc           
        \         P                  P                  p\        V P                  4       EF  w  r#V P
                  P                  W#3V4      pV P                  P                  W$3,          pV P                  P                  W#3,          pVP                  V,          pVP                  V,          p. p	. p
V F  pV F  pVP                  4       pVP                  4       pW8w  g   K+  VP                  VP                  8X  g   KH  V P                  W4      '       d   Ka  V	P                  V4       V
P                  VP                  4       K  	  K  	  V Uu. uF   pW9  g   K  VP                  V
9  g   K  VNK"  	  ppV Uu. uF   pW9  g   K  VP                  V
9  g   K  VNK"  	  ppV P                  P!                  W#3R VRVRV	//4       EK  	  R# u upi u upi )added_constraintsremoved_constraintsr{   N)r
   rF  r  rk   r   r   r   r9   r	   r:   r   rS   rq   r  rn   r{   r   )r+   r  r   r(   r   r   ru  old_constraintsnew_constraintsalt_constraintsalt_constraints_nameold_cnew_c	old_c_dec	new_c_deccadd_constraintsrem_constraintss   &                 r$   r   0MigrationAutodetector.create_altered_constraints  s    ..::%+D,@,@%A!I!0044'N #oo44Y5NOO"mm2293HIO-55kBO-55kBO O#% (,E % 1 1 3I % 1 1 3I!.!JJ%**4 $ P P!! ! (..u5,33EJJ? - )  )(A+ 01>R0R (   )(A+ 01>R0R (   $$++++_--.M &B6
s$   G&G9GGG%Gc           
         V P                   P                  4        FT  w  w  pppV P                  W4      pVR ,           F-  pV P                  V\        P
                  ! VVR7      VR7       K/  	  KV  	  R# )r  r>  r!  N)r{   rZ   r  r  r
   rF  r+   r   r(   r  r   r?  s   &     r$   r   0MigrationAutodetector.generate_added_constraints6  s     #66<<> 
;;IRL-.ABB
"",,#-#- ". #  C ?r#   c           
         V P                   P                  4        FK  w  w  pppVR ,           F5  pV P                  V\        P                  ! VVP
                  R7      4       K7  	  KM  	  R# )r  r]  N)r{   rZ   r  r
   r  rq   )r+   r   r(   r  r?  s   &    r$   r   2MigrationAutodetector.generate_removed_constraintsF  sk     #66<<> 
-.CDD
""//#-'__ E ?r#   c                    V P                   P                  4        F_  w  w  pppV P                  W4      pVR ,           F8  pV P                  V\        P
                  ! VVP                  VR7      VR7       K:  	  Ka  	  R# )r{   )r(   rq   r?  r!  N)r{   rZ   r  r  r
   AlterConstraintrq   r  s   &     r$   r   2MigrationAutodetector.generate_altered_constraintsT  s     #66<<> 
;;IRL-.CDD
""..#-'__#-
 ". #  E ?r#   c                  a R p\        SP                  R4      '       d   SP                  P                  pMVP                  W3,          pVP	                  4        Fm  w  w  rgp\
        ;QJ d-    V3R lVP                  4        4       F  '       g   K   RM"	  RM! V3R lVP                  4        4       4      '       g   Kf  V RV 2p M	  \        SRR 4      p	V	e   Rp
T	pM\        VV V4      w  r\        WR \        P                  P                  4      .p\        SP                  RR 4      '       dY   \        SP                  P                  V V4      w  rVP                  \        VVR \        P                  P                  4      4       V# )	Nr>   c              3   B   <"   T F  pSVP                   8H  x  K  	  R # 5ir'   )rl   )rN   rW  rr   s   & r$   rP   JMigrationAutodetector._get_dependencies_for_foreign_key.<locals>.<genexpr>m  s#      )8 ]777)8s   TFr   swappable_settingr   r   )ra   rl   r>   r$  rZ   r   r   r   r   r   r%   r   r   rn   )r   r(   rr   project_stateremote_field_modelr$  remote_app_labelremote_model_namero   r	  dep_app_labeldep_object_namer   through_app_labelthrough_object_names   &&f&           r$   r'  7MigrationAutodetector._get_dependencies_for_foreign_keye  s   !5%%w//!&!3!3!9!9%//	0EFIAJAR=5!v3 )/333 )/   -=+=Q?P>Q)R& BS $E+>E()M/O-=".*M  6I6N6N6U6U

 5%%y$775E""**62
 #%'',,33	 r#   c           	        . p\         P                  ! VP                  4      P                  p\	        V P
                  V P                  ,
          4      pV F  w  rVpV P                  P                   WV3,          P                  V4      pVP                  '       d   VP                  P                  '       g   VP                  V9   g   Kt  VP                  \        VVVP                  \        P                  P                  4      4       K  	  V# r'   )r	   Q
expressionreferenced_base_fieldsrk   r   r   r:   rq  rl   r>   rq   rn   r   r%   r   )	r+   rr   r   r  newly_added_fieldsr   r(   added_field_nameadded_fields	   &&       r$   r  ;MigrationAutodetector._get_dependencies_for_generated_field  s    !'%*:*:!;!R!R#D$7$7$:M:M$MN7I3I#3--..y/DEOO K ((([-E-E-K-K-K!!%;;##'!"#((+0077	 8J r#   c           	     :  a . pV P                   P                  W3,          pR  VP                  P                  4        4       pV F  p\        ;QJ dF    V3R l\        P
                  P                  VP                  4       4       F  '       g   K   RM;	  RM7! V3R l\        P
                  P                  VP                  4       4       4      '       g   K  VP                  \        VVVP                  \        P                  P                  4      4       K  	  V# )c              3   L   "   T F  qP                   '       g   K  Vx  K  	  R # 5ir'   )r  )rN   fs   & r$   rP   \MigrationAutodetector._get_generated_field_dependencies_for_removed_field.<locals>.<genexpr>  s     R'B!kkAA'Bs   $
$c              3   0   <"   T F  vrSV8H  x  K  	  R # 5ir'   r   )rN   rq   r  r0   s   &  r$   rP   r    s       SHD d" Ss   TF)r9   r	   ro   r   r   Model_get_expr_referencesr  rn   r   rq   r%   r   )r+   r   r(   r0   r   r   generated_fieldsrr   s   &&&f    r$   r  IMigrationAutodetector._get_generated_field_dependencies_for_removed_field  s     oo,,Y-BCR{'9'9'@'@'BR%Es  & A A%BRBR Ssss  & A A%BRBR S   ##'!"

+0077	 & r#   c           	     
   . pV P                   P                  W3,          pVP                  P                  4        FD  pVP                  '       g   K  VP                  V P                  VVVV P                   4      4       KF  	  V# )z3Return foreign key dependencies of the given model.)r:   r	   ro   r   r%  r&  r'  )r+   r   r(   r   r   rr   s   &&&   r$   r  1MigrationAutodetector._get_dependencies_for_model  sw    mm**9+@A ''..0E   ##::!"	 1 r#   c              #    a aa"   \        S P                  4       EF  w  ooS P                  P                  SS3S4      pS P                  P
                  SV3,          pS P                  P
                  SS3,          pVP                  P                  V4      pV'       dG   V Uu0 uF9  p\        ;QJ d    . VVV 3R  lV 4       F  NK  	  5M! VVV 3R  lV 4       4      kK;  	  upM	\        4       pVP                  P                  V4      pV'       d   \        V4      M	\        4       pWW8w  g   EK  . pV F|  p	V	 Fs  p
VP                  V
4      pVP                  '       g   K(  VP                  P                  '       g   KF  VP                  S P                  SSVS P                  4      4       Ku  	  K~  	  VVSSV3x  EK  	  R# u upi 5i)c              3   b   <"   T F$  pSP                   P                  SSV3V4      x  K&  	  R # 5ir'   )r|   r   )rN   nr   r(   r+   s   & r$   rP   MMigrationAutodetector._get_altered_foo_together_operations.<locals>.<genexpr>  s5      !'A ++//J0JANN!'s   ,/N)rk   r   r   r   r9   r	   r:   r   rX   r}   rq  rl   r>   r&  r'  )r+   r  r   r   ru  r  r  r  r   foo_togethersr0   rr   r   r(   s   f&          @@r$   r  :MigrationAutodetector._get_altered_foo_together_operations  s    %+D,@,@%A!Iz!0044J'N #oo44Y5NOO"mm229j3HIO (//33K@I  #,
 #,	 E !'EE !'  #, U  (//33K@I*3II%!%.M&3
 / 9 9* E ---%2D2D2J2J2J(// $ F F$-$.$)$(MM	!" '4 &/   O &Bs1   B G%G5/G$/GG2,G#GA
Gc           
     x   V P                  VP                  4       F  w  pppppV\        P                  8X  d-   V Uu0 uF   pVV P                  WE3,          9  g   K  VkK"  	  ppVP                  V4      pV'       g   V'       g   Km  V P                  VV! RR V/VP                  V/B VR7       K  	  R# u upi rq   r!  Nr   )r  r  r
   r  r  rD  r  )	r+   r   r  r  r   r(   r   rO   removal_values	   &&       r$   &_generate_removed_altered_foo_together<MigrationAutodetector._generate_removed_altered_foo_together  s     66y7L7LM
J999 "+!*==i>STU E!*   &229=M		"" ',5,A,A=+Q ". #  Ns   B7B7c                D    V P                  \        P                  4       R # r'   )r/  r
   r  r*   s   &r$   r   >MigrationAutodetector.generate_removed_altered_unique_together  s    33J4R4RSr#   c           
         V P                  VP                  4       FJ  w  pppppVP                  V4      pW78w  g   K"  V P                  VV! RR V/VP                  V/B VR7       KL  	  R# r-  )r  r  rD  r  )r+   r   r  r  r   r(   r   r.  s   &&      r$   _generate_altered_foo_together4MigrationAutodetector._generate_altered_foo_together  s|     66y7L7LM
%229=M)""T:T)2G2G1ST!- #  Nr#   c                D    V P                  \        P                  4       R # r'   )r4  r
   r  r*   s   &r$   r   6MigrationAutodetector.generate_altered_unique_together)  s    ++J,J,JKr#   c           	        V P                   P                  V P                  V P                  4      p\	        V4       F  w  r#V P
                  P                  W#3V4      pV P                  P                  W$3,          pV P                  P                  W#3,          pVP                  P                  R 4      pVP                  P                  R 4      pWx8w  g   K  V P                  V\        P                  ! VVR7      4       K  	  R# )db_table)rq   tableN)r   unionr   r   rk   r   r   r9   r	   r:   r   r  r
   AlterModelTable)	r+   models_to_checkr   r(   r   r   ru  old_db_table_namenew_db_table_names	   &        r$   r   /MigrationAutodetector.generate_altered_db_table,  s    ..44  $":":
 &,O%<!I!0044'N #oo44Y5NOO"mm2293HIO / 7 7 ; ;J G / 7 7 ; ;J G 5""..'/ &=r#   c           	        V P                   P                  V P                  V P                  4      p\	        V4       F  w  r#V P
                  P                  W#3V4      pV P                  P                  W$3,          pV P                  P                  W#3,          pVP                  P                  R 4      pVP                  P                  R 4      pWx8w  g   K  V P                  V\        P                  ! VVR7      4       K  	  R# )db_table_comment)rq   table_commentN)r   r;  r   r   rk   r   r   r9   r	   r:   r   r  r
   AlterModelTableComment)	r+   r=  r   r(   r   r   ru  old_db_table_commentnew_db_table_comments	   &        r$   r   7MigrationAutodetector.generate_altered_db_table_commentA  s    ..44  $":":
 &,O%<!I!0044'N #oo44Y5NOO"mm2293HIO#2#:#:#>#>?Q#R #2#:#:#>#>?Q#R #;""55'&: &=r#   c           	     <   V P                   P                  V P                  V P                  V P                  V P
                  ,          V P                  V P                  ,          4      p\        V4       EF  w  r#V P                  P                  W#3V4      pV P                  P                  W$3,          pV P                  P                  W#3,          pVP                  P                  4        UUu/ uF  w  rxV\         P"                  9   g   K  WxbK   	  p	ppVP                  P                  4        UUu/ uF  w  rxV\         P"                  9   g   K  WxbK   	  p
ppW8w  g   K  V P%                  V\&        P                   ! VV
R7      4       EK  	  R# u uppi u uppi )z
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).
)rq   r   N)r   r;  r   r   r   r   r~   r   rk   r   r   r9   r	   r:   r   rZ   r   ALTER_OPTION_KEYSr  r
   )r+   r=  r   r(   r   r   ru  rd   rO   old_optionsnew_optionss   &          r$   r   .MigrationAutodetector.generate_altered_optionsW  sy    ..44  $$##d&9&99$"9"99
 &,O%<!I!0044'N #oo44Y5NOO"mm2293HIO #2"9"9"?"?"A"AJC+=== 
"A   #2"9"9"?"?"A"AJC+=== 
"A  
 )""00' +# &=
s   0FF4FFc           
        \        V P                  4       EFF  w  rV P                  P                  W3V4      pV P                  P
                  W3,          pV P                  P
                  W3,          pVP                  P                  R 4      VP                  P                  R 4      8w  g   K  . pVP                  P                  R 4      '       dG   VP                  \        VVVP                  R ,          \        P                  P                  4      4       V P                  V\        P                  ! VVP                  P                  R 4      R7      VR7       EKI  	  R# )r  r;  r!  N)rk   r   r   r   r9   r	   r:   r   rn   r   r%   r   r  r
   r  )r+   r   r(   r   r   ru  r   s   &      r$   r   <MigrationAutodetector.generate_altered_order_with_respect_to  s9   %+D,@,@%A!I!0044'N #oo44Y5NOO"mm2293HIO&&**' ((,,-DEF
  ""**../FGG ''+%&+334KL/44;;	 ""66'.=.E.E.I.I3/ ". # 	- &Br#   c           	        \        V P                  4       F  w  rV P                  P                  W3V4      pV P                  P
                  W3,          pV P                  P
                  W3,          pVP                  VP                  8w  g   K{  V P                  V\        P                  ! VVP                  R 7      4       K  	  R# ))rq   r9  N)rk   r   r   r   r9   r	   r:   r9  r  r
   AlterModelManagers)r+   r   r(   r   r   ru  s   &     r$   r   /MigrationAutodetector.generate_altered_managers  s    %+D,@,@%A!I!0044'N #oo44Y5NOO"mm2293HIO''?+C+CC""11'!0!9!9 &Br#   c           	        VP                  4       p/ p\        VP                  4       4       EF{  w  rgV'       g   K  RpV F  p	V	^ ,          V8X  g   K  T	p M	  VfA   V P                  P	                  V4      '       g    V F  p
VR3WVV
P
                  3&   K  	  W Kq  Vf   ^pM)V P                  V^,          4      ;'       g    ^ ^,           p\        V4       F  w  rV^ 8X  d$   V'       d   V
P                  P                  V4       RV,          .pV'       d   VP                  V4       MGV^ 8X  d   V'       g   VP                  R4       M&VP                  V
P                  4       R,          4       RP                  V4      pWn3WVV
P
                  3&   V^,          pWn        K  	  EK~  	  VP                  4        F;  pV F2  p
V
P                   Uu. uF  qP                  W4      NK  	  upV
n        K4  	  K=  	  V# u upi )z
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.
Nr   z%04ir   :Nd   Nr  )r   rW   rZ   r;   ask_initialrq   parse_number	enumerater   rn   suggest_namejoinr   r   )r+   rI   rE   rH   leavesname_mapr   r   app_leafleafr   next_numberinew_name_partsr   rR  s   &&&&            r$   rC   'MigrationAutodetector.arrange_for_graph  s    !!#%)'--/%:!IH7i'#H 
 (C(CI(N(N!+I=F<TH89 ",&#00!=BBaG )* 56h**11(;"(;"6!7!")).9!VH")))4")))*@*@*B4*HI88N39B8MY^^45q !) !6- &;J "..*J'	090F0F*0F1LL&0F*	& ( +
 *s   G=c           	        / pVP                  4        FL  w  rEV FA  pVP                   F.  w  rxVP                  V\        4       4      P	                  V4       K0  	  KC  	  KN  	  \        V4      p	Rp
W8w  d=   \        V	4      p
V	P
                  ! V	 Uu. uF  qCP                  VR4      NK  	  up!   KB  \        V4       F  pWI9  g   K  W K  	  V# u upi )a	  
Take changes from arrange_for_graph() and set of app labels, and return
a modified set of changes which trims out as many migrations that are
not in app_labels as possible. Note that some other migrations may
still be present as they may be required dependencies.
Nr   )rZ   r   r   r}   r   r   r   rW   )r+   rI   
app_labelsapp_dependenciesr   r   r   r  rq   required_appsold_required_appss   &&&        r$   rD   #MigrationAutodetector._trim_to_apps  s     %,]]_!I'	+4+A+A'M$//	35AEEmT ,B ( &5 J 0 #M 2  GTU})&&y"5}U gI-& '  Vs   Cc                    \         P                  ! RV4      ;p'       d   \        V^,          4      # \         P                  ! RV4      pV'       d   \        V^ ,          4      # R# )u   
Given a migration name, try to extract a number from the beginning of
it. For a squashed migration such as '0001_squashed_0004…', return the
second number. If no number is found, return None.
z.*_squashed_(\d+)z^\d+N)researchintmatch)clsrq   squashed_matchrk  s   &&  r$   rU  "MigrationAutodetector.parse_number   sO      YY';TBB>B~a())$'uQx= r#   )r{   rz   r<   r9   ry   r   r   r   r   r   r   r   r   r   r~   r   r   r;   r|   r  r   r"  ro  r   r:   r'   )NNN)NN)NF)=r   r   r   r   __doc__r?   rI   rM   rt   rB   r   r   staticmethodr   r   r   r   r   r  r  r   r   r   r   r   r   r   r   r  r   r  r   r   r   r   r   r  r   r   r   r   r'  r  r  r  r  r/  r   r4  r   r   r   r   r   r   rC   rD   classmethodrU  r"   r3   r4   s   @r$   r7   r7   +   sc    
G
%NhT
.( 
 
(v"pK$$^K@R.B"H\|)Vwr<"|#IJJ6
pL!
FzRxWr	"TH0d " + +Z** .`2T L*,&P D 2h6  r#   r7   )!r[   rh  collectionsr   r   enumr   graphlibr   	itertoolsr   django.confr   	django.dbr	   django.db.migrationsr
   django.db.migrations.migrationr   &django.db.migrations.operations.modelsr   django.db.migrations.optimizerr   django.db.migrations.questionerr   django.db.migrations.utilsr   r   r   django.utils.functionalr   r   r7   r   r#   r$   <module>r     s]     	 /  &     + 4 D = ? 
 4'$&LM'(a ar#   