Giter Site home page Giter Site logo

django-rename-app's Introduction

django-rename-app

A Django Management Command to rename existing Django Applications.

PyPI version

Installation

pip install django-rename-app.

Add to your Django settings.py INSTALLED_APPS:

INSTALLED_APPS = [
    ...
    'django_rename_app',
    ...
]

Usage

python manage.py rename_app <old_app_name> <new_app_name>

For full detailed instructions see https://odwyer.software/blog/how-to-rename-an-existing-django-application

django-rename-app's People

Contributors

kevindice avatar lucas-bremond avatar richardarpanet avatar rip-the-jacker avatar swiss-knight avatar tonioo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

django-rename-app's Issues

Don't attempt to rename table if it doesn't exist

Thanks for this package, it was a big help! One thing I noticed while trying to use it is that the following query was tripping up on models/tables that had been removed at some point from the original app:

query = (
    f'ALTER TABLE "{old_table_name}" '
    f'RENAME TO "{new_table_name}"'
)

Adding IF EXISTS to the query helped to skip tables that no longer exist.

query = (
    f'ALTER TABLE IF EXISTS "{old_table_name}" '
    f'RENAME TO "{new_table_name}"'
)

I can fork and submit a PR if you'd like.

[Bug] Handle truncation of long table names the same way Django does - Postgres

I had a table which would have had a name (after the app rename process) like:

asdfasd_contests_contesttrackattachmentrequirement_contest_track

which is 64 characters long.

As documented here, the default maximum table name for Postgres is 63 characters, so truncation is necessary: https://www.postgresql.org/docs/9.1/sql-syntax-lexical.html#:~:text=By%20default%2C%20NAMEDATALEN%20is%2064,in%20src%2Finclude%2Fpg_config_manual.

The name that I ended up with:
asdfasd_contests_contesttrackattachmentrequirement_contest_trac

How django truncates the table name:
asdfasd_contests_contesttrackattachmentrequirement_contest_7599

I'm looking into how this 7599 is determined - probably just a hash algo.

Print only SQL commands

Hi @odwyersoftware, thank you for this package, it really helped me.

A nice feature would be just print the commands to the console and then we can simply copy & paste instead of adding it to requirements/building docker image/etc.

I can add this feature if you accept it.

Unable to rename tables when they contain uppercase letters

Renaming does not seem possible when a table name contains upper case letters; i.e. psycopg2 doesn't seem to properly handle that case, even so you pass the name within double quotes to the rename_app call:

# python3 manage.py rename_app  "MyProject" "myproject"
Renaming MyProject to myproject
models: {'team': <class 'myproject.models.Team'>, 'topic': <class 'myproject.models.Topic'>, 'mode': <class 'myproject.models.Mode'>}
renaming team table from: MyProject_team to: myproject_team.
Rename query failed: "ALTER TABLE MyProject_team RENAME TO myproject_team"
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/django/db/backends/utils.py", line 87, in _execute
    return self.cursor.execute(sql)
psycopg2.errors.UndefinedTable: relation "myproject_team" does not exist

Fixed by: #9

HEY!

Hey, you're still active on Github, update ur Mega.NZ Lib!
Please...

model_name not defined

Here is the error from line 79:
f"Renaming {model_name} table from: {old_table_name} to: {new_table_name}." NameError: name 'model_name' is not defined

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.