-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
21 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Run SQL statements as part of your migrations with `migrations.RunSQL` | ||
|
||
## Links | ||
|
||
- [RunSQL](https://docs.djangoproject.com/en/5.0/ref/migration-operations/#runsql) | ||
|
||
## Notes | ||
|
||
`migrations.RunSQL` enables you to run raw SQL on your database from within your migration file. | ||
|
||
From the docs: | ||
|
||
You can also pass a list of strings or 2-tuples. The latter is used for passing queries and parameters in the same way as cursor.execute(). These three operations are equivalent: | ||
|
||
```py | ||
migrations.RunSQL("INSERT INTO musician (name) VALUES ('Reinhardt');") | ||
migrations.RunSQL([("INSERT INTO musician (name) VALUES ('Reinhardt');", None)]) | ||
migrations.RunSQL([("INSERT INTO musician (name) VALUES (%s);", ["Reinhardt"])]) | ||
``` | ||
|
||
> I haven't used this myself, but learned about it from someone else and wanted to document it! |