#30204 closed New feature (wontfix)
Allow declaring pre and post migration SQL on a model's Meta class
Reported by: | Nikolas | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 2.1 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
in some cases need feature for do some SQL prior and after migration
for example:
class Meta(): migrations.SQLBefore('truncate table logs') migrations.SQLAfter('insert into table logs("name") values ("initial")')
expect in migrate
RunSQL(''truncate table logs'') . . . # there what do in migrate . . . RunSQL(''insert into table logs("name") values ("initial")')
this feature very help when need some not implemented feature for example constrains or rules, or for easy create datatabse views
Change History (2)
comment:1 by , 6 years ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
Summary: | Add feature for pre and post migrations SQL → Allow declaring pre and post migration SQL on a model's Meta class |
comment:2 by , 6 years ago
Also if you really want to perform operations after a CreateModel
is performed you could register either pre_migrate
or post_migrate
receivers and inspect the plan
to determine if it contains the operation you are looking for. See also #29843 which plans to add pre
and post_operation
signals to allow post_operation.connect(sender=CreateModel)
.
You can edit migrations and add operations as needed. I don't see why the operations would need to be declared on the model.