[FIX] models: allow empty selection list
If a selection field is created with an empty list of choices (e.g. added by submodules), initialise the field as a varchar column (most common). Check if the list exists to avoid crashing while checking the type of the first key. Fixes #3810
This commit is contained in:
parent
68b8286d5f
commit
ac845819ee
|
@ -190,7 +190,7 @@ def get_pg_type(f, type_override=None):
|
|||
elif issubclass(field_type, (fields.char, fields.reference)):
|
||||
pg_type = ('varchar', pg_varchar(f.size))
|
||||
elif issubclass(field_type, fields.selection):
|
||||
if (isinstance(f.selection, list) and isinstance(f.selection[0][0], int))\
|
||||
if (f.selection and isinstance(f.selection, list) and isinstance(f.selection[0][0], int))\
|
||||
or getattr(f, 'size', None) == -1:
|
||||
pg_type = ('int4', 'INTEGER')
|
||||
else:
|
||||
|
|
Loading…
Reference in New Issue