explain me why django-migration defer from sqlall and raise exception in exist table

62 views
Skip to first unread message

madjardi

unread,
Jun 17, 2015, 5:14:12 AM6/17/15
to django...@googlegroups.com
i have existing table created by FDW (Foreign data wrappers)  named 'stateagency_stateagency'.

two models

class StateAgency(models.Model): 
    id 
= models.AutoField(primary_key=True) 
    name 
= models.CharField(max_length=100) 
        
class Meta: 
                managed 
= False



class Document(models.Model): 
    id 
= models.UUIDField(primary_key=True, editable=False, default=uuid.uuid1)  
    stagcy 
= models.ForeignKey(StateAgency, to_field='id')


ti set managed = False
if i run command: python manage.py sqlall, i give that DDL:

CREATE TABLE "statements_document" (
    "id" uuid NOT NULL PRIMARY KEY,
    "stagcy_id" integer NOT NULL
);
"stagcy_id" integer this not foreign key it very important
but when i run python manage.py sqlmigrate statements 0001
CREATE TABLE "statements_document" (
    "id" UUID NOT NULL PRIMARY KEY
);

-- omitted other sql --
ALTER TABLE "statements_document" ADD CONSTRAINT "statem_stagcy_id_fk_stateagency_stateagency_id" FOREIGN KEY ("stagcy_id") REFERENCES "stateagency_stateagency" ("id") DEFERRABLE INITIALLY DEFERRED;
NOTE:
django use FOREIGN KEY and when i run python manage.py migrate i catch exception, but table already exists

django.db.utils.ProgrammingError: referenced relation "stateagency_stateagency" is not a table

why it have this behavior?
how i can create migration without giving a reference, or by indicating 'stateagency_stateagency' table.
Reply all
Reply to author
Forward
0 new messages