Ignore existing table during migration. / Manage.py

I have a question about the possibility of migrating Django when there is an existing table.

ContentData ContentType Faq UserLog TB_TEAM_INF 

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

Since TB_TEAM_INF is a table used by another command, I cannot delete the table. I cannot use a separate database due to project limitations. In this case, I open the migration file, for example 0001_initial.py, and manually delete the model object, TB_TEAM_INF temporarily during the migration.

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

I tried the --exclude = TB_TEAM_INF or --ignore = TB_TEAM_INF option c. /manage.py migrate, but it seems that these options are not accepted. I am using Django 1.7.2.

+5
source share
1 answer

Add the managed parameter 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 created for this model.

+9
source

Source: https://habr.com/ru/post/1214783/


All Articles