The geonames database has two models that refer to each other. In a postgres database, reference is provided by foreign key relationships. The problem is writing data to the database - writing to one table without having the referenced id in the other table violates a foreign key contraint.
Class Geoname
id = IntegerField(primary_key=True)
admin_1 = foreignkey('Admin1', null=True, db_index=True)
Class Admin1
country = models.ForeignKey(Country, db_index=True)
geoname = models.ForeignKey(Geoname, related_name="admin1_set", db_index=True)
Is there a way to write to a postgres database with this schema, avoiding violating foreign key contraints?
If not, I think a possible solution might be to drop admin_1 from geoname class, but would django still pick up on geoname.admin1_set? Remember, the data is being written directly to the database without the ORM - i think backwards relations are something that is created by the django ORM - I don't know how they are represented at the database level).