Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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

pks on the other side
  • Loading branch information...
commit 2fc4e8273b221bc97bdbb3c8a729c863a7c977e3 1 parent ee39365
@coleifer authored
Showing with 9 additions and 1 deletion.
  1. +9 −1 peewee.py
View
10 peewee.py
@@ -898,7 +898,15 @@ def parse_delete_query(self, query):
def field_sql(self, field):
attrs = field.attributes
attrs['column_type'] = self.get_field(field.get_db_field())
- parts = [self.quote(field.db_column), field.template]
+ template = field.template
+
+ if isinstance(field, ForeignKeyField):
+ to_pk = field.rel_model._meta.primary_key
+ if not isinstance(to_pk, PrimaryKeyField):
+ template = to_pk.template
+ attrs.update(to_pk.attributes)
+
+ parts = [self.quote(field.db_column), template]
if not field.null:
parts.append('NOT NULL')
if field.primary_key:
Please sign in to comment.
Something went wrong with that request. Please try again.