tortoise / tortoise/tortoise-orm

add an option to create raw SQL statement in tortoise makemigrations.

Open
#2,242 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
5.6k
Forks
516
Avg merge
2d 21h
Merged PRs (30d)
9

Description

Is your feature request related to a problem? Please describe.
I wish to add a field like data = fields.JSONField(default=dict) and tweak SQL statement to make default not NULL. (with default '{}' in SQL statement)

Describe the solution you'd like
While this is possible to do manually now, I wish some command line options that populates ops.RunSQL instead of ops.AddField, so I don't need to run tortoise sqlmigrate and copy paste to migration file.
maybe tortoise makemigrations --raw or tortoise makemigrations --sql ?

Describe alternatives you've considered
Tweak the migration file manually, but would be quicker to do if I can have SQL statement generated with migration file.

Additional context
https://github.com/tortoise/tortoise-orm/discussions/2233

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the tortoise makemigrations command and how it differs from tortoise sqlmigrate. Compare the generated ops.AddField migration with the requested ops.RunSQL output, using the proposed --raw or --sql behavior as the scope. Done means a documented command option generates a migration containing the appropriate raw SQL statement.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli, databases
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.