aladagemre / django_uuid_migrator

Automatically adds a unique uuid field to a given Django model

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Django UUID Migrator

When you want to add a unique UUIDField to your Django model, creating 3 consecutive migration files is necessary to avoid unique constraint violation.

This app automatically creates 3 migration scripts for a given Django model so that the model has unique uuid field after the operation.

  • Migration 1: Add uuid field with null=True
  • Migration 2: Populate db with random uuid.
  • Migration 3: Add unique constraint to uuid field (remove null allowance).

See Django Migrations Documentation - Migrations that add unique fields section for more information.

Installation

If you don't use pipx, you're missing out. Here are installation instructions.

Simply run:

$ pipx install .

Usage

To use it:

$ uuid-migrator /Users/user/projects/bookstore/bookstore/books Book

Arguments are:

  • the folder path containing the app (/Users/user/projects/bookstore/bookstore/books)
  • model name (Book)

About

Automatically adds a unique uuid field to a given Django model

License:GNU General Public License v3.0


Languages

Language:Python 100.0%