2121from plain .models .backends .utils import names_digest , split_identifier , truncate_name
2222from plain .models .constraints import Deferrable
2323from plain .models .fields import Field
24- from plain .models .fields .related import ForeignKey , RelatedField
24+ from plain .models .fields .related import ForeignKeyField , RelatedField
2525from plain .models .fields .reverse_related import ManyToManyRel
2626from plain .models .indexes import Index
2727from plain .models .sql import Query
3535 from plain .models .base import Model
3636 from plain .models .constraints import BaseConstraint
3737 from plain .models .fields import Field
38- from plain .models .fields .related import ForeignKey , ManyToManyField
38+ from plain .models .fields .related import ForeignKeyField , ManyToManyField
3939 from plain .models .fields .reverse_related import ManyToManyRel
4040
4141logger = logging .getLogger ("plain.models.backends.schema" )
@@ -55,7 +55,7 @@ def _is_relevant_relation(relation: Any, altered_field: Field) -> bool:
5555 if altered_field .primary_key :
5656 # Foreign key constraint on the primary key, which is being altered.
5757 return True
58- # ForeignKey always targets 'id'
58+ # ForeignKeyField always targets 'id'
5959 return altered_field .name == "id"
6060
6161
@@ -244,7 +244,7 @@ def table_sql(self, model: type[Model]) -> tuple[str, list[Any]]:
244244 if extra_params :
245245 params .extend (extra_params )
246246 # FK.
247- if isinstance (field , ForeignKey ) and field .db_constraint :
247+ if isinstance (field , ForeignKeyField ) and field .db_constraint :
248248 to_table = field .remote_field .model .model_options .db_table
249249 field_name = field .remote_field .field_name
250250 if field_name is None :
@@ -586,7 +586,7 @@ def add_field(self, model: type[Model], field: Field) -> None:
586586 if db_params ["check" ]:
587587 definition += " " + self .sql_check_constraint % db_params
588588 if (
589- isinstance (field , ForeignKey )
589+ isinstance (field , ForeignKeyField )
590590 and self .connection .features .supports_foreign_keys
591591 and field .db_constraint
592592 ):
@@ -768,7 +768,7 @@ def _alter_field(
768768 fks_dropped = set ()
769769 if (
770770 self .connection .features .supports_foreign_keys
771- and isinstance (old_field , ForeignKey )
771+ and isinstance (old_field , ForeignKeyField )
772772 and old_field .db_constraint
773773 and self ._field_should_be_altered (
774774 old_field ,
@@ -839,11 +839,11 @@ def _alter_field(
839839 # True | False | False | True
840840 # True | False | True | True
841841 if (
842- isinstance (old_field , ForeignKey )
842+ isinstance (old_field , ForeignKeyField )
843843 and old_field .db_index
844844 and not old_field .primary_key
845845 and (
846- not (isinstance (new_field , ForeignKey ) and new_field .db_index )
846+ not (isinstance (new_field , ForeignKeyField ) and new_field .db_index )
847847 or new_field .primary_key
848848 )
849849 ):
@@ -1007,10 +1007,10 @@ def _alter_field(
10071007 # True | True | True | False
10081008 if (
10091009 (
1010- not (isinstance (old_field , ForeignKey ) and old_field .db_index )
1010+ not (isinstance (old_field , ForeignKeyField ) and old_field .db_index )
10111011 or old_field .primary_key
10121012 )
1013- and isinstance (new_field , ForeignKey )
1013+ and isinstance (new_field , ForeignKeyField )
10141014 and new_field .db_index
10151015 and not new_field .primary_key
10161016 ):
@@ -1056,10 +1056,10 @@ def _alter_field(
10561056 # Does it have a foreign key?
10571057 if (
10581058 self .connection .features .supports_foreign_keys
1059- and isinstance (new_field , ForeignKey )
1059+ and isinstance (new_field , ForeignKeyField )
10601060 and (
10611061 fks_dropped
1062- or not isinstance (old_field , ForeignKey )
1062+ or not isinstance (old_field , ForeignKeyField )
10631063 or not old_field .db_constraint
10641064 )
10651065 and new_field .db_constraint
@@ -1070,7 +1070,7 @@ def _alter_field(
10701070 # Rebuild FKs that pointed to us if we previously had to drop them
10711071 if drop_foreign_keys :
10721072 for _ , rel in rels_to_update :
1073- if isinstance (rel .field , ForeignKey ) and rel .field .db_constraint :
1073+ if isinstance (rel .field , ForeignKeyField ) and rel .field .db_constraint :
10741074 self .execute (
10751075 self ._create_fk_sql (rel .related_model , rel .field , "_fk" )
10761076 )
@@ -1462,7 +1462,7 @@ def _field_should_be_altered(
14621462 ) or (old_path , old_args , old_kwargs ) != (new_path , new_args , new_kwargs )
14631463
14641464 def _field_should_be_indexed (self , model : type [Model ], field : Field ) -> bool :
1465- if isinstance (field , ForeignKey ):
1465+ if isinstance (field , ForeignKeyField ):
14661466 return bool (field .remote_field ) and field .db_index and not field .primary_key
14671467 return False
14681468
@@ -1480,7 +1480,7 @@ def _rename_field_sql(
14801480 }
14811481
14821482 def _create_fk_sql (
1483- self , model : type [Model ], field : ForeignKey , suffix : str
1483+ self , model : type [Model ], field : ForeignKeyField , suffix : str
14841484 ) -> Statement :
14851485 table = Table (model .model_options .db_table , self .quote_name )
14861486 name = self ._fk_constraint_name (model , field , suffix )
@@ -1505,7 +1505,7 @@ def _create_fk_sql(
15051505 )
15061506
15071507 def _fk_constraint_name (
1508- self , model : type [Model ], field : ForeignKey , suffix : str
1508+ self , model : type [Model ], field : ForeignKeyField , suffix : str
15091509 ) -> ForeignKeyName :
15101510 def create_fk_name (* args : Any , ** kwargs : Any ) -> str :
15111511 return self .quote_name (self ._create_index_name (* args , ** kwargs ))
0 commit comments