Is it possible to use settings at “migration time” when using GeneratedField?
My model:
class Foo(model.Model):
name = models.CharField(max_length=30)
link = models.GeneratedField(
expression=Concat(
models.Value(settings.SOME_HOST),
models.Value("/api/v2/"),
"name"
),
output_field=models.URLField(),
db_persist=False,
)
link
used to be a property, but I want to migrate to GeneratedField
.
Unfortunately, the code above creates the migration with the actual value of settings.SOME_HOST
, and not with the settings name.
# settings.py
SOME_HOST = "https://test-api.example.com"
# 0001_foo.py
...
('link', models.GeneratedField(db_persist=False, expression=django.db.models.functions.text.Concat(models.Value('https://test-api.example.com'), models.Value('/api/v2/'), 'name'), output_field=models.URLField()))
...
This breaks my current development flow, since the value of settings.SOME_HOST
comes from settings at the time and from the environment on which I run makemigrations
, and not from the time the migrations are actually being applied on the target enviroment.