8

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.

ronnefeldt
  • 2,083
  • 23
  • 24

1 Answers1

12

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.

catavaran
  • 44,703
  • 8
  • 98
  • 85