-
Notifications
You must be signed in to change notification settings - Fork 107
Closed
Labels
Description
Hi! Thank you for the useful tool!
I have some problems/questions about generating migration for partitioned models.
For example we have model:
class MyModel(PostgresPartitionedModel):
class PartitioningMeta:
method = PostgresPartitioningMethod.RANGE
key = ["foreign_field"]
title = models.CharField(...)
foreign_field = models.ForeignKey(...)
migration looks like:
operations = [
psqlextra.backend.migrations.operations.create_partitioned_model.PostgresCreatePartitionedModel(...),
psqlextra.backend.migrations.operations.add_default_partition.PostgresAddDefaultPartition(...),
migrations.AddField(
model_name='MyModel',
name='foreign_field',
),
So, firstly table with "simple" fields is created and after that foreign field will be added to the table. But if this field is used as a partition key we will have the error:
"Model 'MyModel' is not properly configured to be partitioned. Field 'foreign_field' in partitioning key ['foreign_field'] is not a valid field on 'MyModel'". Because the model doesn't "see" this field on executing the PostgresCreatePartitionedModel operation. Why relations are adding after table creation? Maybe it is better to combine this?
rvinzent, dtrinchet and nvta-sbiyyala