---
slug: "recreate-migrationマイグレーションを再作成するBASH関数"
title: "recreate-migration: BASH Function to Recreate Migration"
description: "\n\n\nRollback the migration, delete all migration scripts, and then redo the schema migrations."
url: "https://www.ytyng.com/en/blog/recreate-migrationマイグレーションを再作成するBASH関数"
publish_date: "2011-09-10T11:32:12Z"
created: "2011-09-10T11:32:12Z"
updated: "2026-02-27T08:22:17.246Z"
categories: ["Django"]
keywords: ""
featured_image_url: "https://media.ytyng.com/resize/20230812/79c29c38e19f4cb0a19bd1bb48968db5.png.webp?width=768"
has_video: false
has_music: false
video_urls: []
music_urls: []
lang: "en"
---

# recreate-migration: BASH Function to Recreate Migration

<div class="document">


<p>Rollback the migration, delete all migration scripts, and then redo the schema migrations.</p>
<p>※ To migrate to zero, all records in the database will be deleted.</p>
<p>Bash script</p>
<pre class="literal-block">recreate-migration(){
    if [ "$1" ]; then
        ./manage.py migrate $1 zero
        rm $1/migrations/00??_*.py*
        ./manage.py schemamigration $1 --initial
        ./manage.py migrate $1
    else
        echo "usage: recreate-migration &lt;app-name&gt;"
    fi
}
</pre>
</div>
