Skip to content

Commit

Permalink
fix #152
Browse files Browse the repository at this point in the history
  • Loading branch information
PetrDlouhy committed Mar 13, 2020
1 parent 28d1185 commit a3a3f81
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions categories/migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ def field_exists(app_name, model_name, field_name):
cursor = connection.cursor()
field_info = connection.introspection.get_table_description(cursor, table_name)
field_names = [f.name for f in field_info]

# Return True if the many to many table exists
field = model._meta.get_field(field_name)
if hasattr(field, 'm2m_db_table'):
m2m_table_name = field.m2m_db_table()
m2m_field_info = connection.introspection.get_table_description(cursor, m2m_table_name)
if m2m_field_info:
return True

return field_name in field_names


Expand Down

0 comments on commit a3a3f81

Please sign in to comment.