3

I have a database that cannot use multiple schemas due to some legacy software on it, and it needs to share space with a new Django application. Django's built-in tables names conflict with some of the existing ones, so I wanted to add a prefix to all of the table names.

I found various stackoverflow posts such as How to rename all django's default auth, permission,groups tables? Django Database Prefix and they mention a few plugins such as https://github.com/benslavin/django-db-prefix and https://pypi.python.org/pypi/django-table-prefix/0.0.5 - but all of these are ancient, and don't work from Django 1.8 and on (I'm running 1.11)

Is there any solution for Django 1.11? I've looked everywhere, but the existing plugins don't work, and every feature request submitted to Django itself has been closed as wontfix. I tried updating the plugins to 1.11, but they are honestly way over my head.

Specifically, I want to add a prefix to ALL tables - not just the ones in my particular project - including Django's built-in ones. So I'd want "DJANGO_AUTH" to become "PREFIX_DJANGO_AUTH" for instance.

In case it matters, the database is Oracle.

Chris Burrus
  • 187
  • 9
  • 1
    I think you can specify how you want the Django table named : https://docs.djangoproject.com/en/2.0/ref/models/options/#db-table – HenryM Mar 01 '18 at 18:32
  • Really weird that you cannot have another schema in Oracle database, is it really so? – wolfrevokcats Mar 01 '18 at 18:41
  • The legacy code is really old, and won't work with multiple schemas. It may not be impossible, but would be 100x easier if I could avoid it. – Chris Burrus Mar 01 '18 at 18:45
  • Posted an answer that solves changing the names of multiple names here: https://stackoverflow.com/a/53374381/3601660 . This won't fix tables from apps you don't control though. – c z Nov 19 '18 at 12:13

2 Answers2

1

Although the ans coming so late, I finally got the ans:

  1. Install the app

    pip install django-db-prefix
    
  2. Include the apps in Settings.py

    INSTALLED_APPS = ['django_db_prefix',]
    
  3. Adding the prefix in Settings.py

    DB_PREFIX = "foo_"
    
W Kenny
  • 1,855
  • 22
  • 33
0

You should be able to choose the table name you want using the Meta class in your model.

https://docs.djangoproject.com/en/2.0/ref/models/options/#db-table

class MyModel(models.Model)

    class Meta:
        db_table = 'yourtablename'

Otherwise the default is to join the app_name to the class name to create teh tablename.

wobbily_col
  • 11,390
  • 12
  • 62
  • 86
  • I should have clarified - I want to rename ALL tables, including the built in ones such as django.contrib.auth tables. I added a note for clarification - your solution only seems to apply to models that I create, not built-in django apps as well as plugins. – Chris Burrus Mar 01 '18 at 18:44
  • Ok, but I am not sure how to do do that. Doesn't sound too nice. – wobbily_col Mar 01 '18 at 20:00