Skip to content
This repository
Browse code

Smarter field creation for foreign keys when dealing with non-integer

pks on the other side
  • Loading branch information...
commit 2fc4e8273b221bc97bdbb3c8a729c863a7c977e3 1 parent ee39365
Charles Leifer authored

Showing 1 changed file with 9 additions and 1 deletion. Show diff stats Hide diff stats

  1. 10  peewee.py
10  peewee.py
@@ -898,7 +898,15 @@ def parse_delete_query(self, query):
898 898
     def field_sql(self, field):
899 899
         attrs = field.attributes
900 900
         attrs['column_type'] = self.get_field(field.get_db_field())
901  
-        parts = [self.quote(field.db_column), field.template]
  901
+        template = field.template
  902
+
  903
+        if isinstance(field, ForeignKeyField):
  904
+            to_pk = field.rel_model._meta.primary_key
  905
+            if not isinstance(to_pk, PrimaryKeyField):
  906
+                template = to_pk.template
  907
+                attrs.update(to_pk.attributes)
  908
+
  909
+        parts = [self.quote(field.db_column), template]
902 910
         if not field.null:
903 911
             parts.append('NOT NULL')
904 912
         if field.primary_key:

0 notes on commit 2fc4e82

Please sign in to comment.
Something went wrong with that request. Please try again.