allow fields redefining - check column names with names used in constraints

This commit is contained in:
collerek
2020-12-18 10:43:24 +01:00
parent e98300233e
commit 2d74b7bd47
4 changed files with 110 additions and 88 deletions

View File

@ -198,7 +198,15 @@ class BaseField(FieldInfo):
return False
@classmethod
def construct_contraints(cls) -> List:
def construct_constraints(cls) -> List:
"""
Converts list of ormar constraints into sqlalchemy ForeignKeys.
Has to be done dynamically as sqlalchemy binds ForeignKey to the table.
And we need a new ForeignKey for subclasses of current model
:return: List of sqlalchemy foreign keys - by default one.
:rtype: List[sqlalchemy.schema.ForeignKey]
"""
return [
sqlalchemy.schema.ForeignKey(
con.name, ondelete=con.ondelete, onupdate=con.onupdate
@ -221,7 +229,7 @@ class BaseField(FieldInfo):
return sqlalchemy.Column(
cls.alias or name,
cls.column_type,
*cls.construct_contraints(),
*cls.construct_constraints(),
primary_key=cls.primary_key,
nullable=cls.nullable and not cls.primary_key,
index=cls.index,