Setup:
1) Create 2 models and db (postgres)
2) init migrations ...
3) add a fields.OneToOneRelation(..., null=False) to one of the models
4) migrate
5) upgrade
Results in:
-- upgrade --
ALTER TABLE "table1" ADD "foreign_key" UUID NOT NULL UNIQUE;
-- downgrade --
ALTER TABLE "table1" DROP COLUMN "foreign_key";
This however does not enforce the foreign key relationship to table 2! In other words one can add rows with unique random values without errors.
Setup: 1) Create 2 models and db (postgres) 2) init migrations ... 3) add a fields.OneToOneRelation(..., null=False) to one of the models 4) migrate 5) upgrade
Results in: -- upgrade -- ALTER TABLE "table1" ADD "foreign_key" UUID NOT NULL UNIQUE; -- downgrade -- ALTER TABLE "table1" DROP COLUMN "foreign_key";
This however does not enforce the foreign key relationship to table 2! In other words one can add rows with unique random values without errors.