Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ignoring existing table when ./manage.py migrate

I have a question about Django's migration feature when there is an existing table.

ContentData
ContentType
Faq
UserLog
TB_TEAM_INF

When I try to do "./manage.py migrate" so it can create the 5 tables above from models.py, I got an error message because there is an existing table, TB_TEAM_INF.

Since TB_TEAM_INF is a table being used by another team, I cannot remove the table. I cannot use a separated database either due to constraints of the project. In this case I open the migration file like 0001_initial.py and manually remove the model object, TB_TEAM_INF temporarily during migration.

Is there a better way to ignore existing tables when "./manage.py migrate" rather than manually editing the migration file?

I tried --exclude=TB_TEAM_INF or --ignore=TB_TEAM_INF option with ./manage.py migrate but it seems those options are not accepted. I am using Django 1.7.2.

like image 682
ronnefeldt Avatar asked Mar 06 '15 03:03

ronnefeldt


1 Answers

Add the managed option to your model definition:

class TB_TEAM_INF(models.Model):
    ...
    class Meta:
        managed = False

Excerpt from the documentation:

If False, no database table creation or deletion operations will be performed for this model.

like image 111
catavaran Avatar answered Sep 22 '22 16:09

catavaran