MakeMigrations with SpatiaLite and GeoDjango

I am trying to run python manage.py makemigrations after running python manage.py inspectdb > models.py without any errors, but I am getting a lot of errors with makemigrations and I have no idea how to solve these. Some of these errors are:

ERRORS:
whale.GeometryColumnsAuth.f_geometry_column: (fields.E311) 'GeometryColumns.f_geometry_column' must be unique because it is referenced by a foreign key.
        HINT: Add unique=True to this field or add a UniqueConstraint (without condition) in the model Meta.constraints.
whale.GeometryColumnsFieldInfos.f_geometry_column: (fields.E311) 'GeometryColumns.f_geometry_column' must be unique because it is referenced by a foreign key.
        HINT: Add unique=True to this field or add a UniqueConstraint (without condition) in the model Meta.constraints.
whale.GeometryColumnsStatistics.f_geometry_column: (fields.E311) 'GeometryColumns.f_geometry_column' must be unique because it is referenced by a foreign key.
        HINT: Add unique=True to this field or add a UniqueConstraint (without condition) in the model Meta.constraints.

I have tried to solve this by:

    class Meta:
        #managed = False
        db_table = 'geometry_columns_auth'
        constraints = [
            UniqueConstraint(fields=['f_geometry_column'], name='unique_f_geometry_column')
        ]

But, this has not resolved my errors. My GeometryColumnsAuth looks like:

class GeometryColumnsAuth(models.Model):
    f_table_name = models.OneToOneField(GeometryColumns, models.DO_NOTHING, db_column='f_table_name', primary_key=True)  # The composite primary key (f_table_name, f_geometry_column) found, that is not supported. The first column is selected.
    f_geometry_column = models.ForeignKey(GeometryColumns, models.DO_NOTHING, db_column='f_geometry_column', to_field='f_geometry_column', related_name='geometrycolumnsauth_f_geometry_column_set')
    read_only = models.IntegerField()
    hidden = models.IntegerField()

    class Meta:
        #managed = False
        db_table = 'geometry_columns_auth'
        constraints = [
            UniqueConstraint(fields=['f_geometry_column'], name='unique_f_geometry_column')
        ]

How can I resolve these errors?

Welcome @johnwallx !

The issue is in your GeometryColumns model, not GeomertyColumnsAuth. It’s telling you that the f_geometry_column is not a unique field.

What does your GeometryColumns model look like?

Thank you for the welcome, Ken!

My GeometryColumns looks like:

class GeometryColumns(models.Model):
    f_table_name = models.TextField(primary_key=True)  # The composite primary key (f_table_name, f_geometry_column) found, that is not supported. The first column is selected.
    f_geometry_column = models.TextField()
    geometry_type = models.IntegerField()
    coord_dimension = models.IntegerField()
    srid = models.ForeignKey('SpatialRefSys', models.DO_NOTHING, db_column='srid')
    spatial_index_enabled = models.IntegerField()

    class Meta:
        managed = False
        db_table = 'geometry_columns'

This is not a unique field, it cannot be the target of a foreign key definition.

Note:

Is a starting point, not a finishing point. After running inspectdb, you do need to review the models and make adjustments based upon items that may not have been identified by inspectdb.

See the docs at django-admin and manage.py | Django documentation | Django for more details.

Perfecto! Thank you Ken!