-
-
Notifications
You must be signed in to change notification settings - Fork 31.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Clarified SeparateDatabaseAndState docs and added example of changing ManyToManyField. #12523
Clarified SeparateDatabaseAndState docs and added example of changing ManyToManyField. #12523
Conversation
The example is drawn from a draft blog post I have - it's maybe not the best since it uses an empty |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@adamchainz Thanks 👍 I would move an example to the howto/writing-migrations.txt
(with a specific use case) and ref it in docs/ref/migration-operations.txt
. I used migrations.SeparateDatabaseAndState
few times and IMO moving from a custom to an auto-generated intermediate table for ManyToManyField
is a better example because it uses both database_operations
and state_operations
, e.g. (sorry for a typos and not representative names)
migrations.SeparateDatabaseAndState(
database_operations=[
# Rename a custom intermediate table to an auto-generated name.
migrations.RunSQL(
'''
ALTER TABLE x RENAME TO y
''',
'''
ALTER TABLE y RENAME TO x
''',
),
],
state_operations=[
migrations.AlterUniqueTogether(
name='customintermediatemodel',
unique_together=set(),
),
migrations.RemoveField(
model_name='customintermediatemodel',
name='foreign_key_1',
),
migrations.RemoveField(
model_name='customintermediatemodel',
name='foreign_key_2',
),
migrations.AlterField(
model_name='model1',
name='model_2_objs',
field=models.ManyToManyField(to='my_app.Model2'),
),
migrations.DeleteModel(
name='CustomIntermediateModel',
),
],
What do you think?
Updated. I went the other way and used a migration to add the |
f47f5a1
to
3b4c3e1
Compare
3b4c3e1
to
d8fb929
Compare
@adamchainz Thanks 👍 I pushed minor edits and added |
d8fb929
to
263d70f
Compare
Thanks, I pushed a version of the advice on |
263d70f
to
62a0875
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Super stuff. Thanks @adamchainz (and others).
… ManyToManyField. Co-Authored-By: Mariusz Felisiak <felisiak.mariusz@gmail.com> Co-Authored-By: Carlton Gibson <carlton.gibson@noumenal.es> Co-Authored-By: René Fleschenberg <rene@fleschenberg.net>
38075d1
to
2e08dc7
Compare
Cheers all for review, I added you all as coauthors :) |
Merged in a9ee687. |
The
SeparateDatabaseAndState
documentation has always been too short and non-visual for how often one ends up using it (at least, I do). This adds an example and rewords it to point toRunSQL.state_operations
and be less patronizing about avoiding it.