0

In an old project there was an app (let's call it oldapp). I am maintaining this project and I have to rename the app to something else (let's say newapp). The problem is that database tables have been created with the oldapp_ prefix.

I want to avoid to re-creating the database with new prefixes, for obvious reasons.

So, is this possible to rename the app without disturbing the project?

UPDATE: This is one of the errors I am getting: relation "newapp_dma" does not exist

xpanta
  • 8,124
  • 15
  • 60
  • 104
  • Why do you want to rename it? – Burhan Khalid Jun 05 '14 at 12:07
  • I ask myself the same question. I have to. Other people will start contributing to this project soon with apps. Each app must have a certain name. The first app was created with a name that does not abide with the rules and it will cause confusion to other contributors. I need to rename it. – xpanta Jun 05 '14 at 12:12
  • 1
    Use south : http://south.aeracode.org/ – ruddra Jun 05 '14 at 12:13
  • Will `South` rename database tables? I might not want to do that (because project is complex and I am new to it and I don't want to affect the database at the moment) – xpanta Jun 05 '14 at 12:17
  • See also http://stackoverflow.com/questions/4566978/renaming-an-app-with-django-and-south?rq=1 (which almost qualifies as a duplicate question). –  Jun 05 '14 at 12:19
  • It is not a duplicate. I have checked it. I have said in my question that I want to avoid new prefixes. I want to keep my database "as is" – xpanta Jun 05 '14 at 12:21
  • I did say "almost"; it's useful to have the other question cross-linked. –  Jun 05 '14 at 12:26
  • I don't understand the fear of renaming your database tables, though. Obvious reasons aren't obvious to everyone; could you explain that a bit? –  Jun 05 '14 at 12:27
  • South renames dbtable unfortunately . But as u see, django uses ORM, so how will db structure not renaming help you to understand the project? – ruddra Jun 05 '14 at 12:29
  • @Evert, I am in this project for 2 weeks, the previous maintainer (was in the project for 2 years) is gone and nobody can find him. I need to keep database tables because there is a huge amount of documentation that has been produced based on the table-names and I do not want to disrupt the whole team (which involves people from all over the globe). He made this mistake of not naming the app the way he should. Now I need to correct it (If there is a way) – xpanta Jun 05 '14 at 12:37
  • Ok. Sounds like bad management that's not under your control: if they want proper app names, but not rename and rebuild the documentation (documentation should have variables for things like database table names. In fact, the table names should not be in the documentation if this is all Django based, since the database is supposed to be hidden). For such a big project, there should be other people that could agree that the documentation (and other stuff) should be fixed to agree with the app naming policy (and thus rewrite docs as well). Anyway, good luck with whatever solution you use. –  Jun 05 '14 at 12:41

1 Answers1

2

You can, but I wouldn't advise it. For consistency, migrate your data to the newapp name (possibly using South, or simply do some manual renaming in the database).

If you must, have a look at the db_table in your Meta subclass inside your app classes:

class Something(Model):

  class Meta:
    db_table = 'newapp_something'

See the docs.

But, this will cause confusion at some point, using inconsistent names.