1

I have moved my table from app_a to other app_b using db_table. I initially added meta information as,

# app_b.models.ppy
class Table(models.Model)
# all fields
class Meta:
    db_table = 'app_a_table'
    app_label = 'app_a'

If I make any changes in this table in app_b, migrations is not generating new migration file under migration folder. It says.

No changes detected in app 'app_b'

I tried from this ans, and commented app_label = 'app_a'. Now after migration it detects the changes and create the migration file.

Then I execute python manage.py migrate command, it is constantly asking to delete original table app_a_table.

The following content types are stale and need to be deleted:

    app_a | table

Any objects related to these content types by a foreign key will also
be deleted. Are you sure you want to delete these content types?
If you're unsure, answer 'no'.

    Type 'yes' to continue, or 'no' to cancel: no

How do I suppress this notification? How do I tell django migration that this table exists in different app?

Community
  • 1
  • 1
Netro
  • 6,063
  • 5
  • 32
  • 51
  • You should create a mirgation, that creates a new table. copies the data and deletes the old one. Don't forget the references. – Klaus D. May 30 '16 at 07:26
  • @KlausD. if the table is large that would lead considerable down time. – e4c5 May 30 '16 at 08:35

1 Answers1

2

After I moved my table from app_a to other app_b using db_table and app_label. Migrations are working if I run them only for app_a.

python manage.py makemigrations app_a

This command run migration for app_b

Netro
  • 6,063
  • 5
  • 32
  • 51