{"title":"Migration Operations","version":"5.1","locale":"ko","docname":"ref/migration-operations","url":"/ko/5.1/ref/migration-operations/","canonical":"https://djangodocs.dev/ko/5.1/ref/migration-operations/","summary":"Migration files are composed of one or more Operations, objects that declaratively record what the migration should do to your database.","html":"<span id=\"migration-operations\"></span><h1>Migration Operations<a class=\"heading-anchor\" href=\"#module-django.db.migrations.operations\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h1>\n<p>Migration files are composed of one or more <code class=\"docutils literal notranslate\">Operation</code>s, objects that\ndeclaratively record what the migration should do to your database.</p>\n<p>Django also uses these <code class=\"docutils literal notranslate\">Operation</code> objects to work out what your models\nlooked like historically, and to calculate what changes you’ve made to\nyour models since the last migration so it can automatically write\nyour migrations; that’s why they’re declarative, as it means Django can\neasily load them all into memory and run through them without touching\nthe database to work out what your project should look like.</p>\n<p>There are also more specialized <code class=\"docutils literal notranslate\">Operation</code> objects which are for things like\n<a class=\"reference internal\" href=\"/ko/5.1/topics/migrations/#data-migrations\"><span class=\"std std-ref\">data migrations</span></a> and for advanced manual database\nmanipulation. You can also write your own <code class=\"docutils literal notranslate\">Operation</code> classes if you want\nto encapsulate a custom change you commonly make.</p>\n<p>If you need an empty migration file to write your own <code class=\"docutils literal notranslate\">Operation</code> objects\ninto, use <code class=\"docutils literal notranslate\">python manage.py makemigrations --empty yourappname</code>, but be aware\nthat manually adding schema-altering operations can confuse the migration\nautodetector and make resulting runs of <a class=\"reference internal\" href=\"/ko/5.1/ref/django-admin/#django-admin-makemigrations\"><code class=\"xref std std-djadmin docutils literal notranslate\">makemigrations</code></a> output\nincorrect code.</p>\n<p>All of the core Django operations are available from the\n<code class=\"docutils literal notranslate\">django.db.migrations.operations</code> module.</p>\n<p>For introductory material, see the <a class=\"reference internal\" href=\"/ko/5.1/topics/migrations/\"><span class=\"doc\">migrations topic guide</span></a>.</p>\n<section id=\"schema-operations\">\n<h2>Schema Operations<a class=\"heading-anchor\" href=\"#schema-operations\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<section id=\"createmodel\">\n<h3><code class=\"docutils literal notranslate\">CreateModel</code><a class=\"heading-anchor\" href=\"#createmodel\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.db.migrations.operations.CreateModel\">\n<em class=\"property\"><span class=\"k\">class</span> </em><span class=\"sig-name descname\">CreateModel</span><span class=\"sig-paren\">(</span><em class=\"sig-param\">name</em>, <em class=\"sig-param\">fields</em>, <em class=\"sig-param\">options<span class=\"o\">=</span><span class=\"default_value\">None</span></em>, <em class=\"sig-param\">bases<span class=\"o\">=</span><span class=\"default_value\">None</span></em>, <em class=\"sig-param\">managers<span class=\"o\">=</span><span class=\"default_value\">None</span></em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.db.migrations.operations.CreateModel\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>Creates a new model in the project history and a corresponding table in the\ndatabase to match it.</p>\n<p><code class=\"docutils literal notranslate\">name</code> is the model name, as would be written in the <code class=\"docutils literal notranslate\">models.py</code> file.</p>\n<p><code class=\"docutils literal notranslate\">fields</code> is a list of 2-tuples of <code class=\"docutils literal notranslate\">(field_name, field_instance)</code>.\nThe field instance should be an unbound field (so just\n<code class=\"docutils literal notranslate\">models.CharField(...)</code>, rather than a field taken from another model).</p>\n<p><code class=\"docutils literal notranslate\">options</code> is an optional dictionary of values from the model’s <code class=\"docutils literal notranslate\">Meta</code> class.</p>\n<p><code class=\"docutils literal notranslate\">bases</code> is an optional list of other classes to have this model inherit from;\nit can contain both class objects as well as strings in the format\n<code class=\"docutils literal notranslate\">&quot;appname.ModelName&quot;</code> if you want to depend on another model (so you inherit\nfrom the historical version). If it’s not supplied, it defaults to inheriting\nfrom the standard <code class=\"docutils literal notranslate\">models.Model</code>.</p>\n<p><code class=\"docutils literal notranslate\">managers</code> takes a list of 2-tuples of <code class=\"docutils literal notranslate\">(manager_name, manager_instance)</code>.\nThe first manager in the list will be the default manager for this model during\nmigrations.</p>\n</section>\n<section id=\"deletemodel\">\n<h3><code class=\"docutils literal notranslate\">DeleteModel</code><a class=\"heading-anchor\" href=\"#deletemodel\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.db.migrations.operations.DeleteModel\">\n<em class=\"property\"><span class=\"k\">class</span> </em><span class=\"sig-name descname\">DeleteModel</span><span class=\"sig-paren\">(</span><em class=\"sig-param\">name</em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.db.migrations.operations.DeleteModel\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>Deletes the model from the project history and its table from the database.</p>\n</section>\n<section id=\"renamemodel\">\n<h3><code class=\"docutils literal notranslate\">RenameModel</code><a class=\"heading-anchor\" href=\"#renamemodel\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.db.migrations.operations.RenameModel\">\n<em class=\"property\"><span class=\"k\">class</span> </em><span class=\"sig-name descname\">RenameModel</span><span class=\"sig-paren\">(</span><em class=\"sig-param\">old_name</em>, <em class=\"sig-param\">new_name</em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.db.migrations.operations.RenameModel\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>Renames the model from an old name to a new one.</p>\n<p>You may have to manually add\nthis if you change the model’s name and quite a few of its fields at once; to\nthe autodetector, this will look like you deleted a model with the old name\nand added a new one with a different name, and the migration it creates will\nlose any data in the old table.</p>\n</section>\n<section id=\"altermodeltable\">\n<h3><code class=\"docutils literal notranslate\">AlterModelTable</code><a class=\"heading-anchor\" href=\"#altermodeltable\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.db.migrations.operations.AlterModelTable\">\n<em class=\"property\"><span class=\"k\">class</span> </em><span class=\"sig-name descname\">AlterModelTable</span><span class=\"sig-paren\">(</span><em class=\"sig-param\">name</em>, <em class=\"sig-param\">table</em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.db.migrations.operations.AlterModelTable\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>Changes the model’s table name (the <a class=\"reference internal\" href=\"/ko/5.1/ref/models/options/#django.db.models.Options.db_table\" title=\"django.db.models.Options.db_table\"><code class=\"xref py py-attr docutils literal notranslate\">db_table</code></a>\noption on the <code class=\"docutils literal notranslate\">Meta</code> subclass).</p>\n</section>\n<section id=\"altermodeltablecomment\">\n<h3><code class=\"docutils literal notranslate\">AlterModelTableComment</code><a class=\"heading-anchor\" href=\"#altermodeltablecomment\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.db.migrations.operations.AlterModelTableComment\">\n<em class=\"property\"><span class=\"k\">class</span> </em><span class=\"sig-name descname\">AlterModelTableComment</span><span class=\"sig-paren\">(</span><em class=\"sig-param\">name</em>, <em class=\"sig-param\">table_comment</em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.db.migrations.operations.AlterModelTableComment\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>Changes the model’s table comment (the\n<a class=\"reference internal\" href=\"/ko/5.1/ref/models/options/#django.db.models.Options.db_table_comment\" title=\"django.db.models.Options.db_table_comment\"><code class=\"xref py py-attr docutils literal notranslate\">db_table_comment</code></a> option on the <code class=\"docutils literal notranslate\">Meta</code>\nsubclass).</p>\n</section>\n<section id=\"alteruniquetogether\">\n<h3><code class=\"docutils literal notranslate\">AlterUniqueTogether</code><a class=\"heading-anchor\" href=\"#alteruniquetogether\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.db.migrations.operations.AlterUniqueTogether\">\n<em class=\"property\"><span class=\"k\">class</span> </em><span class=\"sig-name descname\">AlterUniqueTogether</span><span class=\"sig-paren\">(</span><em class=\"sig-param\">name</em>, <em class=\"sig-param\">unique_together</em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.db.migrations.operations.AlterUniqueTogether\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>Changes the model’s set of unique constraints (the\n<a class=\"reference internal\" href=\"/ko/5.1/ref/models/options/#django.db.models.Options.unique_together\" title=\"django.db.models.Options.unique_together\"><code class=\"xref py py-attr docutils literal notranslate\">unique_together</code></a> option on the <code class=\"docutils literal notranslate\">Meta</code>\nsubclass).</p>\n</section>\n<section id=\"alterindextogether\">\n<h3><code class=\"docutils literal notranslate\">AlterIndexTogether</code><a class=\"heading-anchor\" href=\"#alterindextogether\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.db.migrations.operations.AlterIndexTogether\">\n<em class=\"property\"><span class=\"k\">class</span> </em><span class=\"sig-name descname\">AlterIndexTogether</span><span class=\"sig-paren\">(</span><em class=\"sig-param\">name</em>, <em class=\"sig-param\">index_together</em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.db.migrations.operations.AlterIndexTogether\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>Changes the model’s set of custom indexes (the <code class=\"docutils literal notranslate\">index_together</code> option on the\n<code class=\"docutils literal notranslate\">Meta</code> subclass).</p>\n<aside class=\"admonition admonition-warning\" role=\"note\">\n<p class=\"admonition-title\">경고</p>\n<p><code class=\"docutils literal notranslate\">AlterIndexTogether</code> is officially supported only for pre-Django 4.2\nmigration files. For backward compatibility reasons, it’s still part of the\npublic API, and there’s no plan to deprecate or remove it, but it should\nnot be used for new migrations. Use\n<a class=\"reference internal\" href=\"#django.db.migrations.operations.AddIndex\" title=\"django.db.migrations.operations.AddIndex\"><code class=\"xref py py-class docutils literal notranslate\">AddIndex</code></a> and\n<a class=\"reference internal\" href=\"#django.db.migrations.operations.RemoveIndex\" title=\"django.db.migrations.operations.RemoveIndex\"><code class=\"xref py py-class docutils literal notranslate\">RemoveIndex</code></a> operations instead.</p>\n</aside>\n</section>\n<section id=\"alterorderwithrespectto\">\n<h3><code class=\"docutils literal notranslate\">AlterOrderWithRespectTo</code><a class=\"heading-anchor\" href=\"#alterorderwithrespectto\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.db.migrations.operations.AlterOrderWithRespectTo\">\n<em class=\"property\"><span class=\"k\">class</span> </em><span class=\"sig-name descname\">AlterOrderWithRespectTo</span><span class=\"sig-paren\">(</span><em class=\"sig-param\">name</em>, <em class=\"sig-param\">order_with_respect_to</em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.db.migrations.operations.AlterOrderWithRespectTo\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>Makes or deletes the <code class=\"docutils literal notranslate\">_order</code> column needed for the\n<a class=\"reference internal\" href=\"/ko/5.1/ref/models/options/#django.db.models.Options.order_with_respect_to\" title=\"django.db.models.Options.order_with_respect_to\"><code class=\"xref py py-attr docutils literal notranslate\">order_with_respect_to</code></a> option on the <code class=\"docutils literal notranslate\">Meta</code>\nsubclass.</p>\n</section>\n<section id=\"altermodeloptions\">\n<h3><code class=\"docutils literal notranslate\">AlterModelOptions</code><a class=\"heading-anchor\" href=\"#altermodeloptions\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.db.migrations.operations.AlterModelOptions\">\n<em class=\"property\"><span class=\"k\">class</span> </em><span class=\"sig-name descname\">AlterModelOptions</span><span class=\"sig-paren\">(</span><em class=\"sig-param\">name</em>, <em class=\"sig-param\">options</em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.db.migrations.operations.AlterModelOptions\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>Stores changes to miscellaneous model options (settings on a model’s <code class=\"docutils literal notranslate\">Meta</code>)\nlike <code class=\"docutils literal notranslate\">permissions</code> and <code class=\"docutils literal notranslate\">verbose_name</code>. Does not affect the database, but\npersists these changes for <a class=\"reference internal\" href=\"#django.db.migrations.operations.RunPython\" title=\"django.db.migrations.operations.RunPython\"><code class=\"xref py py-class docutils literal notranslate\">RunPython</code></a> instances to use. <code class=\"docutils literal notranslate\">options</code>\nshould be a dictionary mapping option names to values.</p>\n</section>\n<section id=\"altermodelmanagers\">\n<h3><code class=\"docutils literal notranslate\">AlterModelManagers</code><a class=\"heading-anchor\" href=\"#altermodelmanagers\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.db.migrations.operations.AlterModelManagers\">\n<em class=\"property\"><span class=\"k\">class</span> </em><span class=\"sig-name descname\">AlterModelManagers</span><span class=\"sig-paren\">(</span><em class=\"sig-param\">name</em>, <em class=\"sig-param\">managers</em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.db.migrations.operations.AlterModelManagers\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>Alters the managers that are available during migrations.</p>\n</section>\n<section id=\"addfield\">\n<h3><code class=\"docutils literal notranslate\">AddField</code><a class=\"heading-anchor\" href=\"#addfield\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.db.migrations.operations.AddField\">\n<em class=\"property\"><span class=\"k\">class</span> </em><span class=\"sig-name descname\">AddField</span><span class=\"sig-paren\">(</span><em class=\"sig-param\">model_name</em>, <em class=\"sig-param\">name</em>, <em class=\"sig-param\">field</em>, <em class=\"sig-param\">preserve_default<span class=\"o\">=</span><span class=\"default_value\">True</span></em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.db.migrations.operations.AddField\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>Adds a field to a model. <code class=\"docutils literal notranslate\">model_name</code> is the model’s name, <code class=\"docutils literal notranslate\">name</code> is\nthe field’s name, and <code class=\"docutils literal notranslate\">field</code> is an unbound Field instance (the thing\nyou would put in the field declaration in <code class=\"docutils literal notranslate\">models.py</code> - for example,\n<code class=\"docutils literal notranslate\">models.IntegerField(null=True)</code>.</p>\n<p>The <code class=\"docutils literal notranslate\">preserve_default</code> argument indicates whether the field’s default\nvalue is permanent and should be baked into the project state (<code class=\"docutils literal notranslate\">True</code>),\nor if it is temporary and just for this migration (<code class=\"docutils literal notranslate\">False</code>) - usually\nbecause the migration is adding a non-nullable field to a table and needs\na default value to put into existing rows. It does not affect the behavior\nof setting defaults in the database directly - Django never sets database\ndefaults and always applies them in the Django ORM code.</p>\n<aside class=\"admonition admonition-warning\" role=\"note\">\n<p class=\"admonition-title\">경고</p>\n<p>On older databases, adding a field with a default value may cause a full\nrewrite of the table. This happens even for nullable fields and may have a\nnegative performance impact. To avoid that, the following steps should be\ntaken.</p>\n<ul class=\"simple\">\n<li><p>Add the nullable field without the default value and run the\n<a class=\"reference internal\" href=\"/ko/5.1/ref/django-admin/#django-admin-makemigrations\"><code class=\"xref std std-djadmin docutils literal notranslate\">makemigrations</code></a> command. This should generate a migration with\nan <code class=\"docutils literal notranslate\">AddField</code> operation.</p></li>\n<li><p>Add the default value to your field and run the <a class=\"reference internal\" href=\"/ko/5.1/ref/django-admin/#django-admin-makemigrations\"><code class=\"xref std std-djadmin docutils literal notranslate\">makemigrations</code></a>\ncommand. This should generate a migration with an <code class=\"docutils literal notranslate\">AlterField</code>\noperation.</p></li>\n</ul>\n</aside>\n</section>\n<section id=\"removefield\">\n<h3><code class=\"docutils literal notranslate\">RemoveField</code><a class=\"heading-anchor\" href=\"#removefield\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.db.migrations.operations.RemoveField\">\n<em class=\"property\"><span class=\"k\">class</span> </em><span class=\"sig-name descname\">RemoveField</span><span class=\"sig-paren\">(</span><em class=\"sig-param\">model_name</em>, <em class=\"sig-param\">name</em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.db.migrations.operations.RemoveField\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>Removes a field from a model.</p>\n<p>Bear in mind that when reversed, this is actually adding a field to a model.\nThe operation is reversible (apart from any data loss, which is irreversible)\nif the field is nullable or if it has a default value that can be used to\npopulate the recreated column. If the field is not nullable and does not have a\ndefault value, the operation is irreversible.</p>\n<aside class=\"admonition-postgresql admonition\" role=\"note\">\n<p class=\"admonition-title\">PostgreSQL</p>\n<p><code class=\"docutils literal notranslate\">RemoveField</code> will also delete any additional database objects that are\nrelated to the removed field (like views, for example). This is because the\nresulting <code class=\"docutils literal notranslate\">DROP COLUMN</code> statement will include the <code class=\"docutils literal notranslate\">CASCADE</code> clause to\nensure <a class=\"reference external\" href=\"https://www.postgresql.org/docs/current/sql-altertable.html#SQL-ALTERTABLE-PARMS-CASCADE\">dependent objects outside the table are also dropped</a>.</p>\n</aside>\n</section>\n<section id=\"alterfield\">\n<h3><code class=\"docutils literal notranslate\">AlterField</code><a class=\"heading-anchor\" href=\"#alterfield\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.db.migrations.operations.AlterField\">\n<em class=\"property\"><span class=\"k\">class</span> </em><span class=\"sig-name descname\">AlterField</span><span class=\"sig-paren\">(</span><em class=\"sig-param\">model_name</em>, <em class=\"sig-param\">name</em>, <em class=\"sig-param\">field</em>, <em class=\"sig-param\">preserve_default<span class=\"o\">=</span><span class=\"default_value\">True</span></em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.db.migrations.operations.AlterField\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>Alters a field’s definition, including changes to its type,\n<a class=\"reference internal\" href=\"/ko/5.1/ref/models/fields/#django.db.models.Field.null\" title=\"django.db.models.Field.null\"><code class=\"xref py py-attr docutils literal notranslate\">null</code></a>, <a class=\"reference internal\" href=\"/ko/5.1/ref/models/fields/#django.db.models.Field.unique\" title=\"django.db.models.Field.unique\"><code class=\"xref py py-attr docutils literal notranslate\">unique</code></a>,\n<a class=\"reference internal\" href=\"/ko/5.1/ref/models/fields/#django.db.models.Field.db_column\" title=\"django.db.models.Field.db_column\"><code class=\"xref py py-attr docutils literal notranslate\">db_column</code></a> and other field attributes.</p>\n<p>The <code class=\"docutils literal notranslate\">preserve_default</code> argument indicates whether the field’s default\nvalue is permanent and should be baked into the project state (<code class=\"docutils literal notranslate\">True</code>),\nor if it is temporary and just for this migration (<code class=\"docutils literal notranslate\">False</code>) - usually\nbecause the migration is altering a nullable field to a non-nullable one and\nneeds a default value to put into existing rows. It does not affect the\nbehavior of setting defaults in the database directly - Django never sets\ndatabase defaults and always applies them in the Django ORM code.</p>\n<p>Note that not all changes are possible on all databases - for example, you\ncannot change a text-type field like <code class=\"docutils literal notranslate\">models.TextField()</code> into a number-type\nfield like <code class=\"docutils literal notranslate\">models.IntegerField()</code> on most databases.</p>\n</section>\n<section id=\"renamefield\">\n<h3><code class=\"docutils literal notranslate\">RenameField</code><a class=\"heading-anchor\" href=\"#renamefield\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.db.migrations.operations.RenameField\">\n<em class=\"property\"><span class=\"k\">class</span> </em><span class=\"sig-name descname\">RenameField</span><span class=\"sig-paren\">(</span><em class=\"sig-param\">model_name</em>, <em class=\"sig-param\">old_name</em>, <em class=\"sig-param\">new_name</em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.db.migrations.operations.RenameField\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>Changes a field’s name (and, unless <a class=\"reference internal\" href=\"/ko/5.1/ref/models/fields/#django.db.models.Field.db_column\" title=\"django.db.models.Field.db_column\"><code class=\"xref py py-attr docutils literal notranslate\">db_column</code></a>\nis set, its column name).</p>\n</section>\n<section id=\"addindex\">\n<h3><code class=\"docutils literal notranslate\">AddIndex</code><a class=\"heading-anchor\" href=\"#addindex\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.db.migrations.operations.AddIndex\">\n<em class=\"property\"><span class=\"k\">class</span> </em><span class=\"sig-name descname\">AddIndex</span><span class=\"sig-paren\">(</span><em class=\"sig-param\">model_name</em>, <em class=\"sig-param\">index</em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.db.migrations.operations.AddIndex\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>Creates an index in the database table for the model with <code class=\"docutils literal notranslate\">model_name</code>.\n<code class=\"docutils literal notranslate\">index</code> is an instance of the <a class=\"reference internal\" href=\"/ko/5.1/ref/models/indexes/#django.db.models.Index\" title=\"django.db.models.Index\"><code class=\"xref py py-class docutils literal notranslate\">Index</code></a> class.</p>\n</section>\n<section id=\"removeindex\">\n<h3><code class=\"docutils literal notranslate\">RemoveIndex</code><a class=\"heading-anchor\" href=\"#removeindex\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.db.migrations.operations.RemoveIndex\">\n<em class=\"property\"><span class=\"k\">class</span> </em><span class=\"sig-name descname\">RemoveIndex</span><span class=\"sig-paren\">(</span><em class=\"sig-param\">model_name</em>, <em class=\"sig-param\">name</em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.db.migrations.operations.RemoveIndex\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>Removes the index named <code class=\"docutils literal notranslate\">name</code> from the model with <code class=\"docutils literal notranslate\">model_name</code>.</p>\n</section>\n<section id=\"renameindex\">\n<h3><code class=\"docutils literal notranslate\">RenameIndex</code><a class=\"heading-anchor\" href=\"#renameindex\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.db.migrations.operations.RenameIndex\">\n<em class=\"property\"><span class=\"k\">class</span> </em><span class=\"sig-name descname\">RenameIndex</span><span class=\"sig-paren\">(</span><em class=\"sig-param\">model_name</em>, <em class=\"sig-param\">new_name</em>, <em class=\"sig-param\">old_name<span class=\"o\">=</span><span class=\"default_value\">None</span></em>, <em class=\"sig-param\">old_fields<span class=\"o\">=</span><span class=\"default_value\">None</span></em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.db.migrations.operations.RenameIndex\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>Renames an index in the database table for the model with <code class=\"docutils literal notranslate\">model_name</code>.\nExactly one of <code class=\"docutils literal notranslate\">old_name</code> and <code class=\"docutils literal notranslate\">old_fields</code> can be provided. <code class=\"docutils literal notranslate\">old_fields</code>\nis an iterable of the strings, often corresponding to fields of\n<code class=\"docutils literal notranslate\">index_together</code> (pre-Django 5.1 option).</p>\n<p>On databases that don’t support an index renaming statement (SQLite and MariaDB\n&lt; 10.5.2), the operation will drop and recreate the index, which can be\nexpensive.</p>\n</section>\n<section id=\"addconstraint\">\n<h3><code class=\"docutils literal notranslate\">AddConstraint</code><a class=\"heading-anchor\" href=\"#addconstraint\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.db.migrations.operations.AddConstraint\">\n<em class=\"property\"><span class=\"k\">class</span> </em><span class=\"sig-name descname\">AddConstraint</span><span class=\"sig-paren\">(</span><em class=\"sig-param\">model_name</em>, <em class=\"sig-param\">constraint</em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.db.migrations.operations.AddConstraint\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>Creates a <a class=\"reference internal\" href=\"/ko/5.1/ref/models/constraints/\"><span class=\"doc\">constraint</span></a> in the database table for\nthe model with <code class=\"docutils literal notranslate\">model_name</code>.</p>\n</section>\n<section id=\"removeconstraint\">\n<h3><code class=\"docutils literal notranslate\">RemoveConstraint</code><a class=\"heading-anchor\" href=\"#removeconstraint\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.db.migrations.operations.RemoveConstraint\">\n<em class=\"property\"><span class=\"k\">class</span> </em><span class=\"sig-name descname\">RemoveConstraint</span><span class=\"sig-paren\">(</span><em class=\"sig-param\">model_name</em>, <em class=\"sig-param\">name</em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.db.migrations.operations.RemoveConstraint\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>Removes the constraint named <code class=\"docutils literal notranslate\">name</code> from the model with <code class=\"docutils literal notranslate\">model_name</code>.</p>\n</section>\n</section>\n<section id=\"special-operations\">\n<h2>Special Operations<a class=\"heading-anchor\" href=\"#special-operations\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<section id=\"runsql\">\n<h3><code class=\"docutils literal notranslate\">RunSQL</code><a class=\"heading-anchor\" href=\"#runsql\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.db.migrations.operations.RunSQL\">\n<em class=\"property\"><span class=\"k\">class</span> </em><span class=\"sig-name descname\">RunSQL</span><span class=\"sig-paren\">(</span><em class=\"sig-param\">sql</em>, <em class=\"sig-param\">reverse_sql<span class=\"o\">=</span><span class=\"default_value\">None</span></em>, <em class=\"sig-param\">state_operations<span class=\"o\">=</span><span class=\"default_value\">None</span></em>, <em class=\"sig-param\">hints<span class=\"o\">=</span><span class=\"default_value\">None</span></em>, <em class=\"sig-param\">elidable<span class=\"o\">=</span><span class=\"default_value\">False</span></em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.db.migrations.operations.RunSQL\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>Allows running of arbitrary SQL on the database - useful for more advanced\nfeatures of database backends that Django doesn’t support directly.</p>\n<p><code class=\"docutils literal notranslate\">sql</code>, and <code class=\"docutils literal notranslate\">reverse_sql</code> if provided, should be strings of SQL to run on\nthe database. On most database backends (all but PostgreSQL), Django will\nsplit the SQL into individual statements prior to executing them.</p>\n<aside class=\"admonition admonition-warning\" role=\"note\">\n<p class=\"admonition-title\">경고</p>\n<p>On PostgreSQL and SQLite, only use <code class=\"docutils literal notranslate\">BEGIN</code> or <code class=\"docutils literal notranslate\">COMMIT</code> in your SQL in\n<a class=\"reference internal\" href=\"/ko/5.1/howto/writing-migrations/#non-atomic-migrations\"><span class=\"std std-ref\">non-atomic migrations</span></a>, to avoid breaking\nDjango’s transaction state.</p>\n</aside>\n<p>You can also pass a list of strings or 2-tuples. The latter is used for passing\nqueries and parameters in the same way as <a class=\"reference internal\" href=\"/ko/5.1/topics/db/sql/#executing-custom-sql\"><span class=\"std std-ref\">cursor.execute()</span></a>. These three operations are equivalent:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code>migrations<span class=\"o\">.</span>RunSQL<span class=\"p\">(</span><span class=\"s2\">&quot;INSERT INTO musician (name) VALUES (&#39;Reinhardt&#39;);&quot;</span><span class=\"p\">)</span>\nmigrations<span class=\"o\">.</span>RunSQL<span class=\"p\">([(</span><span class=\"s2\">&quot;INSERT INTO musician (name) VALUES (&#39;Reinhardt&#39;);&quot;</span><span class=\"p\">,</span> <span class=\"kc\">None</span><span class=\"p\">)])</span>\nmigrations<span class=\"o\">.</span>RunSQL<span class=\"p\">([(</span><span class=\"s2\">&quot;INSERT INTO musician (name) VALUES (</span><span class=\"si\">%s</span><span class=\"s2\">);&quot;</span><span class=\"p\">,</span> <span class=\"p\">[</span><span class=\"s2\">&quot;Reinhardt&quot;</span><span class=\"p\">])])</span>\n</code></pre></div>\n<p>If you want to include literal percent signs in the query, you have to double\nthem if you are passing parameters.</p>\n<p>The <code class=\"docutils literal notranslate\">reverse_sql</code> queries are executed when the migration is unapplied. They\nshould undo what is done by the <code class=\"docutils literal notranslate\">sql</code> queries. For example, to undo the above\ninsertion with a deletion:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code>migrations<span class=\"o\">.</span>RunSQL<span class=\"p\">(</span>\n    sql<span class=\"o\">=</span><span class=\"p\">[(</span><span class=\"s2\">&quot;INSERT INTO musician (name) VALUES (</span><span class=\"si\">%s</span><span class=\"s2\">);&quot;</span><span class=\"p\">,</span> <span class=\"p\">[</span><span class=\"s2\">&quot;Reinhardt&quot;</span><span class=\"p\">])],</span>\n    reverse_sql<span class=\"o\">=</span><span class=\"p\">[(</span><span class=\"s2\">&quot;DELETE FROM musician where name=</span><span class=\"si\">%s</span><span class=\"s2\">;&quot;</span><span class=\"p\">,</span> <span class=\"p\">[</span><span class=\"s2\">&quot;Reinhardt&quot;</span><span class=\"p\">])],</span>\n<span class=\"p\">)</span>\n</code></pre></div>\n<p>If <code class=\"docutils literal notranslate\">reverse_sql</code> is <code class=\"docutils literal notranslate\">None</code> (the default), the <code class=\"docutils literal notranslate\">RunSQL</code> operation is\nirreversible.</p>\n<p>The <code class=\"docutils literal notranslate\">state_operations</code> argument allows you to supply operations that are\nequivalent to the SQL in terms of project state. For example, if you are\nmanually creating a column, you should pass in a list containing an <code class=\"docutils literal notranslate\">AddField</code>\noperation here so that the autodetector still has an up-to-date state of the\nmodel. If you don’t, when you next run <code class=\"docutils literal notranslate\">makemigrations</code>, it won’t see any\noperation that adds that field and so will try to run it again. For example:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code>migrations<span class=\"o\">.</span>RunSQL<span class=\"p\">(</span>\n    <span class=\"s2\">&quot;ALTER TABLE musician ADD COLUMN name varchar(255) NOT NULL;&quot;</span><span class=\"p\">,</span>\n    state_operations<span class=\"o\">=</span><span class=\"p\">[</span>\n        migrations<span class=\"o\">.</span>AddField<span class=\"p\">(</span>\n            <span class=\"s2\">&quot;musician&quot;</span><span class=\"p\">,</span>\n            <span class=\"s2\">&quot;name&quot;</span><span class=\"p\">,</span>\n            models<span class=\"o\">.</span>CharField<span class=\"p\">(</span>max_length<span class=\"o\">=</span><span class=\"mi\">255</span><span class=\"p\">),</span>\n        <span class=\"p\">),</span>\n    <span class=\"p\">],</span>\n<span class=\"p\">)</span>\n</code></pre></div>\n<p>The optional <code class=\"docutils literal notranslate\">hints</code> argument will be passed as <code class=\"docutils literal notranslate\">**hints</code> to the\n<a class=\"reference internal\" href=\"/ko/5.1/topics/db/multi-db/#allow_migrate\" title=\"allow_migrate\"><code class=\"xref py py-meth docutils literal notranslate\">allow_migrate()</code></a> method of database routers to assist them in making\nrouting decisions. See <a class=\"reference internal\" href=\"/ko/5.1/topics/db/multi-db/#topics-db-multi-db-hints\"><span class=\"std std-ref\">힌트</span></a> for more details on\ndatabase hints.</p>\n<p>The optional <code class=\"docutils literal notranslate\">elidable</code> argument determines whether or not the operation will\nbe removed (elided) when <a class=\"reference internal\" href=\"/ko/5.1/topics/migrations/#migration-squashing\"><span class=\"std std-ref\">squashing migrations</span></a>.</p>\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.db.migrations.operations.RunSQL.noop\">\n<span class=\"sig-prename descclassname\">RunSQL.</span><span class=\"sig-name descname\">noop</span><a class=\"heading-anchor\" href=\"#django.db.migrations.operations.RunSQL.noop\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Pass the <code class=\"docutils literal notranslate\">RunSQL.noop</code> attribute to <code class=\"docutils literal notranslate\">sql</code> or <code class=\"docutils literal notranslate\">reverse_sql</code> when you\nwant the operation not to do anything in the given direction. This is\nespecially useful in making the operation reversible.</p>\n</dd></dl>\n\n</section>\n<section id=\"runpython\">\n<h3><code class=\"docutils literal notranslate\">RunPython</code><a class=\"heading-anchor\" href=\"#runpython\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.db.migrations.operations.RunPython\">\n<em class=\"property\"><span class=\"k\">class</span> </em><span class=\"sig-name descname\">RunPython</span><span class=\"sig-paren\">(</span><em class=\"sig-param\">code</em>, <em class=\"sig-param\">reverse_code<span class=\"o\">=</span><span class=\"default_value\">None</span></em>, <em class=\"sig-param\">atomic<span class=\"o\">=</span><span class=\"default_value\">None</span></em>, <em class=\"sig-param\">hints<span class=\"o\">=</span><span class=\"default_value\">None</span></em>, <em class=\"sig-param\">elidable<span class=\"o\">=</span><span class=\"default_value\">False</span></em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.db.migrations.operations.RunPython\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>Runs custom Python code in a historical context. <code class=\"docutils literal notranslate\">code</code> (and <code class=\"docutils literal notranslate\">reverse_code</code>\nif supplied) should be callable objects that accept two arguments; the first is\nan instance of <code class=\"docutils literal notranslate\">django.apps.registry.Apps</code> containing historical models that\nmatch the operation’s place in the project history, and the second is an\ninstance of <a class=\"reference internal\" href=\"/ko/5.1/ref/schema-editor/#django.db.backends.base.schema.BaseDatabaseSchemaEditor\" title=\"django.db.backends.base.schema.BaseDatabaseSchemaEditor\"><code class=\"xref py py-class docutils literal notranslate\">SchemaEditor</code></a>.</p>\n<p>The <code class=\"docutils literal notranslate\">reverse_code</code> argument is called when unapplying migrations. This\ncallable should undo what is done in the <code class=\"docutils literal notranslate\">code</code> callable so that the\nmigration is reversible. If <code class=\"docutils literal notranslate\">reverse_code</code> is <code class=\"docutils literal notranslate\">None</code> (the default), the\n<code class=\"docutils literal notranslate\">RunPython</code> operation is irreversible.</p>\n<p>The optional <code class=\"docutils literal notranslate\">hints</code> argument will be passed as <code class=\"docutils literal notranslate\">**hints</code> to the\n<a class=\"reference internal\" href=\"/ko/5.1/topics/db/multi-db/#allow_migrate\" title=\"allow_migrate\"><code class=\"xref py py-meth docutils literal notranslate\">allow_migrate()</code></a> method of database routers to assist them in making a\nrouting decision. See <a class=\"reference internal\" href=\"/ko/5.1/topics/db/multi-db/#topics-db-multi-db-hints\"><span class=\"std std-ref\">힌트</span></a> for more details on\ndatabase hints.</p>\n<p>The optional <code class=\"docutils literal notranslate\">elidable</code> argument determines whether or not the operation will\nbe removed (elided) when <a class=\"reference internal\" href=\"/ko/5.1/topics/migrations/#migration-squashing\"><span class=\"std std-ref\">squashing migrations</span></a>.</p>\n<p>You are advised to write the code as a separate function above the <code class=\"docutils literal notranslate\">Migration</code>\nclass in the migration file, and pass it to <code class=\"docutils literal notranslate\">RunPython</code>. Here’s an example of\nusing <code class=\"docutils literal notranslate\">RunPython</code> to create some initial objects on a <code class=\"docutils literal notranslate\">Country</code> model:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"kn\">from</span> <span class=\"nn\">django.db</span> <span class=\"kn\">import</span> migrations\n\n\n<span class=\"k\">def</span> <span class=\"nf\">forwards_func</span><span class=\"p\">(</span>apps<span class=\"p\">,</span> schema_editor<span class=\"p\">):</span>\n    <span class=\"c1\"># We get the model from the versioned app registry;</span>\n    <span class=\"c1\"># if we directly import it, it&#39;ll be the wrong version</span>\n    Country <span class=\"o\">=</span> apps<span class=\"o\">.</span>get_model<span class=\"p\">(</span><span class=\"s2\">&quot;myapp&quot;</span><span class=\"p\">,</span> <span class=\"s2\">&quot;Country&quot;</span><span class=\"p\">)</span>\n    db_alias <span class=\"o\">=</span> schema_editor<span class=\"o\">.</span>connection<span class=\"o\">.</span>alias\n    Country<span class=\"o\">.</span>objects<span class=\"o\">.</span>using<span class=\"p\">(</span>db_alias<span class=\"p\">)</span><span class=\"o\">.</span>bulk_create<span class=\"p\">(</span>\n        <span class=\"p\">[</span>\n            Country<span class=\"p\">(</span>name<span class=\"o\">=</span><span class=\"s2\">&quot;USA&quot;</span><span class=\"p\">,</span> code<span class=\"o\">=</span><span class=\"s2\">&quot;us&quot;</span><span class=\"p\">),</span>\n            Country<span class=\"p\">(</span>name<span class=\"o\">=</span><span class=\"s2\">&quot;France&quot;</span><span class=\"p\">,</span> code<span class=\"o\">=</span><span class=\"s2\">&quot;fr&quot;</span><span class=\"p\">),</span>\n        <span class=\"p\">]</span>\n    <span class=\"p\">)</span>\n\n\n<span class=\"k\">def</span> <span class=\"nf\">reverse_func</span><span class=\"p\">(</span>apps<span class=\"p\">,</span> schema_editor<span class=\"p\">):</span>\n    <span class=\"c1\"># forwards_func() creates two Country instances,</span>\n    <span class=\"c1\"># so reverse_func() should delete them.</span>\n    Country <span class=\"o\">=</span> apps<span class=\"o\">.</span>get_model<span class=\"p\">(</span><span class=\"s2\">&quot;myapp&quot;</span><span class=\"p\">,</span> <span class=\"s2\">&quot;Country&quot;</span><span class=\"p\">)</span>\n    db_alias <span class=\"o\">=</span> schema_editor<span class=\"o\">.</span>connection<span class=\"o\">.</span>alias\n    Country<span class=\"o\">.</span>objects<span class=\"o\">.</span>using<span class=\"p\">(</span>db_alias<span class=\"p\">)</span><span class=\"o\">.</span>filter<span class=\"p\">(</span>name<span class=\"o\">=</span><span class=\"s2\">&quot;USA&quot;</span><span class=\"p\">,</span> code<span class=\"o\">=</span><span class=\"s2\">&quot;us&quot;</span><span class=\"p\">)</span><span class=\"o\">.</span>delete<span class=\"p\">()</span>\n    Country<span class=\"o\">.</span>objects<span class=\"o\">.</span>using<span class=\"p\">(</span>db_alias<span class=\"p\">)</span><span class=\"o\">.</span>filter<span class=\"p\">(</span>name<span class=\"o\">=</span><span class=\"s2\">&quot;France&quot;</span><span class=\"p\">,</span> code<span class=\"o\">=</span><span class=\"s2\">&quot;fr&quot;</span><span class=\"p\">)</span><span class=\"o\">.</span>delete<span class=\"p\">()</span>\n\n\n<span class=\"k\">class</span> <span class=\"nc\">Migration</span><span class=\"p\">(</span>migrations<span class=\"o\">.</span>Migration<span class=\"p\">):</span>\n    dependencies <span class=\"o\">=</span> <span class=\"p\">[]</span>\n\n    operations <span class=\"o\">=</span> <span class=\"p\">[</span>\n        migrations<span class=\"o\">.</span>RunPython<span class=\"p\">(</span>forwards_func<span class=\"p\">,</span> reverse_func<span class=\"p\">),</span>\n    <span class=\"p\">]</span>\n</code></pre></div>\n<p>This is generally the operation you would use to create\n<a class=\"reference internal\" href=\"/ko/5.1/topics/migrations/#data-migrations\"><span class=\"std std-ref\">data migrations</span></a>, run\ncustom data updates and alterations, and anything else you need access to an\nORM and/or Python code for.</p>\n<p>Much like <a class=\"reference internal\" href=\"#django.db.migrations.operations.RunSQL\" title=\"django.db.migrations.operations.RunSQL\"><code class=\"xref py py-class docutils literal notranslate\">RunSQL</code></a>, ensure that if you change schema inside here you’re\neither doing it outside the scope of the Django model system (e.g. triggers)\nor that you use <a class=\"reference internal\" href=\"#django.db.migrations.operations.SeparateDatabaseAndState\" title=\"django.db.migrations.operations.SeparateDatabaseAndState\"><code class=\"xref py py-class docutils literal notranslate\">SeparateDatabaseAndState</code></a> to add in operations that will\nreflect your changes to the model state - otherwise, the versioned ORM and\nthe autodetector will stop working correctly.</p>\n<p>By default, <code class=\"docutils literal notranslate\">RunPython</code> will run its contents inside a transaction on\ndatabases that do not support DDL transactions (for example, MySQL and\nOracle). This should be safe, but may cause a crash if you attempt to use\nthe <code class=\"docutils literal notranslate\">schema_editor</code> provided on these backends; in this case, pass\n<code class=\"docutils literal notranslate\">atomic=False</code> to the <code class=\"docutils literal notranslate\">RunPython</code> operation.</p>\n<p>On databases that do support DDL transactions (SQLite and PostgreSQL),\n<code class=\"docutils literal notranslate\">RunPython</code> operations do not have any transactions automatically added\nbesides the transactions created for each migration. Thus, on PostgreSQL, for\nexample, you should avoid combining schema changes and <code class=\"docutils literal notranslate\">RunPython</code> operations\nin the same migration or you may hit errors like <code class=\"docutils literal notranslate\">OperationalError: cannot\nALTER TABLE &quot;mytable&quot; because it has pending trigger events</code>.</p>\n<p>If you have a different database and aren’t sure if it supports DDL\ntransactions, check the <code class=\"docutils literal notranslate\">django.db.connection.features.can_rollback_ddl</code>\nattribute.</p>\n<p>If the <code class=\"docutils literal notranslate\">RunPython</code> operation is part of a <a class=\"reference internal\" href=\"/ko/5.1/howto/writing-migrations/#non-atomic-migrations\"><span class=\"std std-ref\">non-atomic migration</span></a>, the operation will only be executed in a transaction\nif <code class=\"docutils literal notranslate\">atomic=True</code> is passed to the <code class=\"docutils literal notranslate\">RunPython</code> operation.</p>\n<aside class=\"admonition admonition-warning\" role=\"note\">\n<p class=\"admonition-title\">경고</p>\n<p><code class=\"docutils literal notranslate\">RunPython</code> does not magically alter the connection of the models for you;\nany model methods you call will go to the default database unless you\ngive them the current database alias (available from\n<code class=\"docutils literal notranslate\">schema_editor.connection.alias</code>, where <code class=\"docutils literal notranslate\">schema_editor</code> is the second\nargument to your function).</p>\n</aside>\n<dl class=\"py method\">\n<dt class=\"sig sig-object py\" id=\"django.db.migrations.operations.RunPython.noop\">\n<em class=\"property\"><span class=\"k\">static</span> </em><span class=\"sig-prename descclassname\">RunPython.</span><span class=\"sig-name descname\">noop</span><span class=\"sig-paren\">(</span><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.db.migrations.operations.RunPython.noop\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Pass the <code class=\"docutils literal notranslate\">RunPython.noop</code> method to <code class=\"docutils literal notranslate\">code</code> or <code class=\"docutils literal notranslate\">reverse_code</code> when\nyou want the operation not to do anything in the given direction. This is\nespecially useful in making the operation reversible.</p>\n</dd></dl>\n\n</section>\n<section id=\"separatedatabaseandstate\">\n<h3><code class=\"docutils literal notranslate\">SeparateDatabaseAndState</code><a class=\"heading-anchor\" href=\"#separatedatabaseandstate\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.db.migrations.operations.SeparateDatabaseAndState\">\n<em class=\"property\"><span class=\"k\">class</span> </em><span class=\"sig-name descname\">SeparateDatabaseAndState</span><span class=\"sig-paren\">(</span><em class=\"sig-param\">database_operations<span class=\"o\">=</span><span class=\"default_value\">None</span></em>, <em class=\"sig-param\">state_operations<span class=\"o\">=</span><span class=\"default_value\">None</span></em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.db.migrations.operations.SeparateDatabaseAndState\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>A highly specialized operation that lets you mix and match the database\n(schema-changing) and state (autodetector-powering) aspects of operations.</p>\n<p>It accepts two lists of operations. When asked to apply state, it will use the\n<code class=\"docutils literal notranslate\">state_operations</code> list (this is a generalized version of <a class=\"reference internal\" href=\"#django.db.migrations.operations.RunSQL\" title=\"django.db.migrations.operations.RunSQL\"><code class=\"xref py py-class docutils literal notranslate\">RunSQL</code></a>’s\n<code class=\"docutils literal notranslate\">state_operations</code> argument). When asked to apply changes to the database, it\nwill use the <code class=\"docutils literal notranslate\">database_operations</code> list.</p>\n<p>If the actual state of the database and Django’s view of the state get out of\nsync, this can break the migration framework, even leading to data loss. It’s\nworth exercising caution and checking your database and state operations\ncarefully. You can use <a class=\"reference internal\" href=\"/ko/5.1/ref/django-admin/#django-admin-sqlmigrate\"><code class=\"xref std std-djadmin docutils literal notranslate\">sqlmigrate</code></a> and <a class=\"reference internal\" href=\"/ko/5.1/ref/django-admin/#django-admin-dbshell\"><code class=\"xref std std-djadmin docutils literal notranslate\">dbshell</code></a> to check\nyour database operations. You can use <a class=\"reference internal\" href=\"/ko/5.1/ref/django-admin/#django-admin-makemigrations\"><code class=\"xref std std-djadmin docutils literal notranslate\">makemigrations</code></a>, especially\nwith <a class=\"reference internal\" href=\"/ko/5.1/ref/django-admin/#cmdoption-makemigrations-dry-run\"><code class=\"xref std std-option docutils literal notranslate\">--dry-run</code></a>, to check your state\noperations.</p>\n<p>For an example using <code class=\"docutils literal notranslate\">SeparateDatabaseAndState</code>, see\n<a class=\"reference internal\" href=\"/ko/5.1/howto/writing-migrations/#changing-a-manytomanyfield-to-use-a-through-model\"><span class=\"std std-ref\">ManyToManyField 를 바꾸어 through  모델을 사용합니다.</span></a>.</p>\n</section>\n</section>\n<section id=\"operation-category\">\n<h2>Operation category<a class=\"heading-anchor\" href=\"#operation-category\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<aside class=\"version-note version-added\" data-version=\"5.1\" role=\"note\">\n<p class=\"version-note-title\">New in Django 5.1</p></aside>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.db.migrations.operations.base.OperationCategory\">\n<em class=\"property\"><span class=\"k\">class</span> </em><span class=\"sig-name descname\">OperationCategory</span><a class=\"heading-anchor\" href=\"#django.db.migrations.operations.base.OperationCategory\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Categories of migration operation used by the <a class=\"reference internal\" href=\"/ko/5.1/ref/django-admin/#django-admin-makemigrations\"><code class=\"xref std std-djadmin docutils literal notranslate\">makemigrations</code></a>\ncommand to display meaningful symbols.</p>\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.db.migrations.operations.base.OperationCategory.ADDITION\">\n<span class=\"sig-name descname\">ADDITION</span><a class=\"heading-anchor\" href=\"#django.db.migrations.operations.base.OperationCategory.ADDITION\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p><em>Symbol</em>: <code class=\"docutils literal notranslate\">+</code></p>\n</dd></dl>\n\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.db.migrations.operations.base.OperationCategory.REMOVAL\">\n<span class=\"sig-name descname\">REMOVAL</span><a class=\"heading-anchor\" href=\"#django.db.migrations.operations.base.OperationCategory.REMOVAL\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p><em>Symbol</em>: <code class=\"docutils literal notranslate\">-</code></p>\n</dd></dl>\n\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.db.migrations.operations.base.OperationCategory.ALTERATION\">\n<span class=\"sig-name descname\">ALTERATION</span><a class=\"heading-anchor\" href=\"#django.db.migrations.operations.base.OperationCategory.ALTERATION\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p><em>Symbol</em>: <code class=\"docutils literal notranslate\">~</code></p>\n</dd></dl>\n\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.db.migrations.operations.base.OperationCategory.PYTHON\">\n<span class=\"sig-name descname\">PYTHON</span><a class=\"heading-anchor\" href=\"#django.db.migrations.operations.base.OperationCategory.PYTHON\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p><em>Symbol</em>: <code class=\"docutils literal notranslate\">p</code></p>\n</dd></dl>\n\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.db.migrations.operations.base.OperationCategory.SQL\">\n<span class=\"sig-name descname\">SQL</span><a class=\"heading-anchor\" href=\"#django.db.migrations.operations.base.OperationCategory.SQL\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p><em>Symbol</em>: <code class=\"docutils literal notranslate\">s</code></p>\n</dd></dl>\n\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.db.migrations.operations.base.OperationCategory.MIXED\">\n<span class=\"sig-name descname\">MIXED</span><a class=\"heading-anchor\" href=\"#django.db.migrations.operations.base.OperationCategory.MIXED\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p><em>Symbol</em>: <code class=\"docutils literal notranslate\">?</code></p>\n</dd></dl>\n\n</dd></dl>\n\n</section>\n<section id=\"writing-your-own\">\n<span id=\"writing-your-own-migration-operation\"></span><h2>Writing your own<a class=\"heading-anchor\" href=\"#writing-your-own\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Operations have a relatively simple API, and they’re designed so that you can\neasily write your own to supplement the built-in Django ones. The basic\nstructure of an <code class=\"docutils literal notranslate\">Operation</code> looks like this:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"kn\">from</span> <span class=\"nn\">django.db.migrations.operations.base</span> <span class=\"kn\">import</span> Operation\n\n\n<span class=\"k\">class</span> <span class=\"nc\">MyCustomOperation</span><span class=\"p\">(</span>Operation<span class=\"p\">):</span>\n    <span class=\"c1\"># If this is False, it means that this operation will be ignored by</span>\n    <span class=\"c1\"># sqlmigrate; if true, it will be run and the SQL collected for its output.</span>\n    reduces_to_sql <span class=\"o\">=</span> <span class=\"kc\">False</span>\n\n    <span class=\"c1\"># If this is False, Django will refuse to reverse past this operation.</span>\n    reversible <span class=\"o\">=</span> <span class=\"kc\">False</span>\n\n    <span class=\"c1\"># This categorizes the operation. The corresponding symbol will be</span>\n    <span class=\"c1\"># displayed by the makemigrations command.</span>\n    category <span class=\"o\">=</span> OperationCategory<span class=\"o\">.</span>ADDITION\n\n    <span class=\"k\">def</span> <span class=\"fm\">__init__</span><span class=\"p\">(</span><span class=\"bp\">self</span><span class=\"p\">,</span> arg1<span class=\"p\">,</span> arg2<span class=\"p\">):</span>\n        <span class=\"c1\"># Operations are usually instantiated with arguments in migration</span>\n        <span class=\"c1\"># files. Store the values of them on self for later use.</span>\n        <span class=\"k\">pass</span>\n\n    <span class=\"k\">def</span> <span class=\"nf\">state_forwards</span><span class=\"p\">(</span><span class=\"bp\">self</span><span class=\"p\">,</span> app_label<span class=\"p\">,</span> state<span class=\"p\">):</span>\n        <span class=\"c1\"># The Operation should take the &#39;state&#39; parameter (an instance of</span>\n        <span class=\"c1\"># django.db.migrations.state.ProjectState) and mutate it to match</span>\n        <span class=\"c1\"># any schema changes that have occurred.</span>\n        <span class=\"k\">pass</span>\n\n    <span class=\"k\">def</span> <span class=\"nf\">database_forwards</span><span class=\"p\">(</span><span class=\"bp\">self</span><span class=\"p\">,</span> app_label<span class=\"p\">,</span> schema_editor<span class=\"p\">,</span> from_state<span class=\"p\">,</span> to_state<span class=\"p\">):</span>\n        <span class=\"c1\"># The Operation should use schema_editor to apply any changes it</span>\n        <span class=\"c1\"># wants to make to the database.</span>\n        <span class=\"k\">pass</span>\n\n    <span class=\"k\">def</span> <span class=\"nf\">database_backwards</span><span class=\"p\">(</span><span class=\"bp\">self</span><span class=\"p\">,</span> app_label<span class=\"p\">,</span> schema_editor<span class=\"p\">,</span> from_state<span class=\"p\">,</span> to_state<span class=\"p\">):</span>\n        <span class=\"c1\"># If reversible is True, this is called when the operation is reversed.</span>\n        <span class=\"k\">pass</span>\n\n    <span class=\"k\">def</span> <span class=\"nf\">describe</span><span class=\"p\">(</span><span class=\"bp\">self</span><span class=\"p\">):</span>\n        <span class=\"c1\"># This is used to describe what the operation does.</span>\n        <span class=\"k\">return</span> <span class=\"s2\">&quot;Custom Operation&quot;</span>\n\n    <span class=\"nd\">@property</span>\n    <span class=\"k\">def</span> <span class=\"nf\">migration_name_fragment</span><span class=\"p\">(</span><span class=\"bp\">self</span><span class=\"p\">):</span>\n        <span class=\"c1\"># Optional. A filename part suitable for automatically naming a</span>\n        <span class=\"c1\"># migration containing this operation, or None if not applicable.</span>\n        <span class=\"k\">return</span> <span class=\"s2\">&quot;custom_operation_</span><span class=\"si\">%s</span><span class=\"s2\">_</span><span class=\"si\">%s</span><span class=\"s2\">&quot;</span> <span class=\"o\">%</span> <span class=\"p\">(</span><span class=\"bp\">self</span><span class=\"o\">.</span>arg1<span class=\"p\">,</span> <span class=\"bp\">self</span><span class=\"o\">.</span>arg2<span class=\"p\">)</span>\n</code></pre></div>\n<p>You can take this template and work from it, though we suggest looking at the\nbuilt-in Django operations in <code class=\"docutils literal notranslate\">django.db.migrations.operations</code> - they cover\na lot of the example usage of semi-internal aspects of the migration framework\nlike <code class=\"docutils literal notranslate\">ProjectState</code> and the patterns used to get historical models, as well\nas <code class=\"docutils literal notranslate\">ModelState</code> and the patterns used to mutate historical models in\n<code class=\"docutils literal notranslate\">state_forwards()</code>.</p>\n<p>Some things to note:</p>\n<ul>\n<li><p>You don’t need to learn too much about <code class=\"docutils literal notranslate\">ProjectState</code> to write migrations;\njust know that it has an <code class=\"docutils literal notranslate\">apps</code> property that gives access to an app\nregistry (which you can then call <code class=\"docutils literal notranslate\">get_model</code> on).</p></li>\n<li><p><code class=\"docutils literal notranslate\">database_forwards</code> and <code class=\"docutils literal notranslate\">database_backwards</code> both get two states passed\nto them; these represent the difference the <code class=\"docutils literal notranslate\">state_forwards</code> method would\nhave applied, but are given to you for convenience and speed reasons.</p></li>\n<li><p>If you want to work with model classes or model instances from the\n<code class=\"docutils literal notranslate\">from_state</code> argument in <code class=\"docutils literal notranslate\">database_forwards()</code> or\n<code class=\"docutils literal notranslate\">database_backwards()</code>, you must render model states using the\n<code class=\"docutils literal notranslate\">clear_delayed_apps_cache()</code> method to make related models available:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"k\">def</span> <span class=\"nf\">database_forwards</span><span class=\"p\">(</span><span class=\"bp\">self</span><span class=\"p\">,</span> app_label<span class=\"p\">,</span> schema_editor<span class=\"p\">,</span> from_state<span class=\"p\">,</span> to_state<span class=\"p\">):</span>\n    <span class=\"c1\"># This operation should have access to all models. Ensure that all models are</span>\n    <span class=\"c1\"># reloaded in case any are delayed.</span>\n    from_state<span class=\"o\">.</span>clear_delayed_apps_cache<span class=\"p\">()</span>\n    <span class=\"o\">...</span>\n</code></pre></div>\n</li>\n<li><p><code class=\"docutils literal notranslate\">to_state</code> in the database_backwards method is the <em>older</em> state; that is,\nthe one that will be the current state once the migration has finished reversing.</p></li>\n<li><p>You might see implementations of <code class=\"docutils literal notranslate\">references_model</code> on the built-in\noperations; this is part of the autodetection code and does not matter for\ncustom operations.</p></li>\n</ul>\n<aside class=\"admonition admonition-warning\" role=\"note\">\n<p class=\"admonition-title\">경고</p>\n<p>For performance reasons, the <a class=\"reference internal\" href=\"/ko/5.1/ref/models/fields/#django.db.models.Field\" title=\"django.db.models.Field\"><code class=\"xref py py-class docutils literal notranslate\">Field</code></a> instances in\n<code class=\"docutils literal notranslate\">ModelState.fields</code> are reused across migrations. You must never change\nthe attributes on these instances. If you need to mutate a field in\n<code class=\"docutils literal notranslate\">state_forwards()</code>, you must remove the old instance from\n<code class=\"docutils literal notranslate\">ModelState.fields</code> and add a new instance in its place. The same is true\nfor the <a class=\"reference internal\" href=\"/ko/5.1/topics/db/managers/#django.db.models.Manager\" title=\"django.db.models.Manager\"><code class=\"xref py py-class docutils literal notranslate\">Manager</code></a> instances in\n<code class=\"docutils literal notranslate\">ModelState.managers</code>.</p>\n</aside>\n<p>As an example, let’s make an operation that loads PostgreSQL extensions (which\ncontain some of PostgreSQL’s more exciting features). Since there’s no model\nstate changes, all it does is run one command:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"kn\">from</span> <span class=\"nn\">django.db.migrations.operations.base</span> <span class=\"kn\">import</span> Operation\n\n\n<span class=\"k\">class</span> <span class=\"nc\">LoadExtension</span><span class=\"p\">(</span>Operation<span class=\"p\">):</span>\n    reversible <span class=\"o\">=</span> <span class=\"kc\">True</span>\n\n    <span class=\"k\">def</span> <span class=\"fm\">__init__</span><span class=\"p\">(</span><span class=\"bp\">self</span><span class=\"p\">,</span> name<span class=\"p\">):</span>\n        <span class=\"bp\">self</span><span class=\"o\">.</span>name <span class=\"o\">=</span> name\n\n    <span class=\"k\">def</span> <span class=\"nf\">state_forwards</span><span class=\"p\">(</span><span class=\"bp\">self</span><span class=\"p\">,</span> app_label<span class=\"p\">,</span> state<span class=\"p\">):</span>\n        <span class=\"k\">pass</span>\n\n    <span class=\"k\">def</span> <span class=\"nf\">database_forwards</span><span class=\"p\">(</span><span class=\"bp\">self</span><span class=\"p\">,</span> app_label<span class=\"p\">,</span> schema_editor<span class=\"p\">,</span> from_state<span class=\"p\">,</span> to_state<span class=\"p\">):</span>\n        schema_editor<span class=\"o\">.</span>execute<span class=\"p\">(</span><span class=\"s2\">&quot;CREATE EXTENSION IF NOT EXISTS </span><span class=\"si\">%s</span><span class=\"s2\">&quot;</span> <span class=\"o\">%</span> <span class=\"bp\">self</span><span class=\"o\">.</span>name<span class=\"p\">)</span>\n\n    <span class=\"k\">def</span> <span class=\"nf\">database_backwards</span><span class=\"p\">(</span><span class=\"bp\">self</span><span class=\"p\">,</span> app_label<span class=\"p\">,</span> schema_editor<span class=\"p\">,</span> from_state<span class=\"p\">,</span> to_state<span class=\"p\">):</span>\n        schema_editor<span class=\"o\">.</span>execute<span class=\"p\">(</span><span class=\"s2\">&quot;DROP EXTENSION </span><span class=\"si\">%s</span><span class=\"s2\">&quot;</span> <span class=\"o\">%</span> <span class=\"bp\">self</span><span class=\"o\">.</span>name<span class=\"p\">)</span>\n\n    <span class=\"k\">def</span> <span class=\"nf\">describe</span><span class=\"p\">(</span><span class=\"bp\">self</span><span class=\"p\">):</span>\n        <span class=\"k\">return</span> <span class=\"s2\">&quot;Creates extension </span><span class=\"si\">%s</span><span class=\"s2\">&quot;</span> <span class=\"o\">%</span> <span class=\"bp\">self</span><span class=\"o\">.</span>name\n\n    <span class=\"nd\">@property</span>\n    <span class=\"k\">def</span> <span class=\"nf\">migration_name_fragment</span><span class=\"p\">(</span><span class=\"bp\">self</span><span class=\"p\">):</span>\n        <span class=\"k\">return</span> <span class=\"s2\">&quot;create_extension_</span><span class=\"si\">%s</span><span class=\"s2\">&quot;</span> <span class=\"o\">%</span> <span class=\"bp\">self</span><span class=\"o\">.</span>name\n</code></pre></div>\n</section>","rootId":"module-django.db.migrations.operations","toc":[{"title":"Schema Operations","anchor":"schema-operations","children":[{"title":"CreateModel","anchor":"createmodel","children":[]},{"title":"DeleteModel","anchor":"deletemodel","children":[]},{"title":"RenameModel","anchor":"renamemodel","children":[]},{"title":"AlterModelTable","anchor":"altermodeltable","children":[]},{"title":"AlterModelTableComment","anchor":"altermodeltablecomment","children":[]},{"title":"AlterUniqueTogether","anchor":"alteruniquetogether","children":[]},{"title":"AlterIndexTogether","anchor":"alterindextogether","children":[]},{"title":"AlterOrderWithRespectTo","anchor":"alterorderwithrespectto","children":[]},{"title":"AlterModelOptions","anchor":"altermodeloptions","children":[]},{"title":"AlterModelManagers","anchor":"altermodelmanagers","children":[]},{"title":"AddField","anchor":"addfield","children":[]},{"title":"RemoveField","anchor":"removefield","children":[]},{"title":"AlterField","anchor":"alterfield","children":[]},{"title":"RenameField","anchor":"renamefield","children":[]},{"title":"AddIndex","anchor":"addindex","children":[]},{"title":"RemoveIndex","anchor":"removeindex","children":[]},{"title":"RenameIndex","anchor":"renameindex","children":[]},{"title":"AddConstraint","anchor":"addconstraint","children":[]},{"title":"RemoveConstraint","anchor":"removeconstraint","children":[]}]},{"title":"Special Operations","anchor":"special-operations","children":[{"title":"RunSQL","anchor":"runsql","children":[]},{"title":"RunPython","anchor":"runpython","children":[]},{"title":"SeparateDatabaseAndState","anchor":"separatedatabaseandstate","children":[]}]},{"title":"Operation category","anchor":"operation-category","children":[]},{"title":"Writing your own","anchor":"writing-your-own","children":[]}],"breadcrumbs":[{"docname":"ref/index","title":"API 레퍼런스","url":"/ko/5.1/ref/"}],"prev":{"docname":"ref/middleware","title":"Middleware","url":"/ko/5.1/ref/middleware/"},"next":{"docname":"ref/models/index","title":"모델","url":"/ko/5.1/ref/models/"},"formats":{"html":"/ko/5.1/ref/migration-operations/","markdown":"/ko/5.1/ref/migration-operations.md","json":"/ko/5.1/ref/migration-operations.json"},"source":"https://github.com/django/django/blob/stable/5.1.x/docs/ref/migration-operations.txt","official":"https://docs.djangoproject.com/ko/5.1/ref/migration-operations/","inVersions":["6.1","6.0","5.2","5.1","5.0","4.2","4.1","4.0","3.2","3.1","3.0","2.2","2.1","2.0","1.11"],"inLocales":["en","zh-hans","fr","ja","id","it","pt-br","ko","es","el","pl"]}