Env: Django 1.8.11 + Postgis

I'm adding some ForeignKeys on a MyModel. The models pointed are in another 
schema ("cartography").

makemigrations

no errors

migrate

One error. Can't create the constraint because the generated name. But I'm 
adding 10 fields, really similar between them. Only one is giving that 
stupid error. I can't specify the constraint name anywhere.

class myModel(models.Model)
    zps_calculated = models.ForeignKey( Cartography_zps, 
verbose_name="zps_calcolato", null=True, blank=True, on_delete=models.SET_NULL)
    zsc_sic_sir_calculated = models.ForeignKey( Cartography_zsc_sic_sir, 
verbose_name="zsc_sic_sir_calcolato", null=True, blank=True, 
on_delete=models.SET_NULL)
    manyothersdata = "xxx"

That is the slice of code generated from sqlmigrate (to inspect the code 
the migration generate). As you see the name of the constraint is the 
error. 1 on 10 fields is giving the error

CREATE INDEX "segnalazioni_f38ba181" ON "segnalazioni" 
("zps_calculated_id");ALTER TABLE "segnalazioni" ADD CONSTRAINT 
"se_zps_calculated_id_6844dce0603174b2_fk_"cartography"."zps"_id" FOREIGN KEY 
("zps_calculated_id") REFERENCES "cartography"."zps" ("id") DEFERRABLE 
INITIALLY DEFERRED;CREATE INDEX "segnalazioni_eb52e53f" ON "segnalazioni" 
("zsc_sic_sir_calculated_id");ALTER TABLE "segnalazioni" ADD CONSTRAINT 
"cc6ce48808e3a5292779a9787d21e5ad" FOREIGN KEY ("zsc_sic_sir_calculated_id") 
REFERENCES "cartography"."zsc_sic_sir" ("id") DEFERRABLE INITIALLY DEFERRED;

That is the name giving the error: 
"se_zps_calculated_id_6844dce0603174b2_fk_"cartography"."zps"_id" I think 
should be something like: "6844dce0603174b2..."

the model NOT giving the error:

class Cartography_zsc_sic_sir(models.Model):
    id = models.AutoField(primary_key=True)
    slug = models.CharField(max_length=40, blank=True, null=True)
    nome = models.CharField(max_length=60, blank=True, null=True)
    the_geom = models.MultiPolygonField(srid=23032, blank=True, null=True )
    objects = models.GeoManager()

    class Meta:
        managed = False
        db_table = '"cartography"."zsc_sic_sir"'
        verbose_name = 'Cartography - zsc_sic_sir'
        verbose_name_plural = 'Cartography - zsc_sic_sir'
        ordering = ["id","slug"]

    def __unicode__(self):
        return self.nome

that is the model giving the error:

class Cartography_zps(models.Model):
    id = models.AutoField(primary_key=True)
    slug = models.CharField(max_length=40, blank=True, null=True)
    the_geom = models.MultiPolygonField(srid=23032, blank=True, null=True )
    objects = models.GeoManager()

    class Meta:
        managed = False
        db_table = '"cartography"."zps"'
        verbose_name = 'Cartography - ZPS'
        verbose_name_plural = 'Cartography - ZPS'
        ordering = ["id","slug"]

    def __unicode__(self):
        return self.slug

Going further I'm investigating in Django code, backwards.

The

 ' %s ADD CONSTRAINT %s FOREIGN KEY (%s) REFERENCES %s (%s)%s;' %

is in /django/db/backends/base/creation.py row 180

using that

qn = self.connection.ops.quote_name

that SHOULD be the %s constraint name value:

qn(truncate_name(r_name, self.connection.ops.max_name_length()))

Anyone have an hint to help me? I'm gonna look what qn does.




-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/82a799ff-78bf-4e75-994a-4d7a1c58dcda%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to