Django 使用 db_table 将 table 移动到其他应用程序并且不删除原始 table
Django move table to other app using db_table and don't delete original table
我已使用 db_table
将我的 table 从 app_a
移动到其他 app_b
。我最初将元信息添加为,
# app_b.models.ppy
class Table(models.Model)
# all fields
class Meta:
db_table = 'app_a_table'
app_label = 'app_a'
如果我在 app_b
中对此 table 进行任何更改,迁移不会在迁移文件夹下生成新的迁移文件。
它说。
No changes detected in app 'app_b'
我从这个 ans 开始尝试,并评论 app_label = 'app_a'
。现在迁移后它会检测到更改并创建迁移文件。
然后我执行python manage.py migrate
命令,它不断要求删除原来的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
如何禁止此通知?我如何告诉 django 迁移这个 table 存在于不同的应用程序中?
在我使用 db_table
和 app_label
将我的 table 从 app_a
移动到其他 app_b
之后。
如果我 运行 迁移仅用于 app_a
,则迁移工作正常。
python manage.py makemigrations app_a
此命令 运行 迁移 app_b
我已使用 db_table
将我的 table 从 app_a
移动到其他 app_b
。我最初将元信息添加为,
# app_b.models.ppy
class Table(models.Model)
# all fields
class Meta:
db_table = 'app_a_table'
app_label = 'app_a'
如果我在 app_b
中对此 table 进行任何更改,迁移不会在迁移文件夹下生成新的迁移文件。
它说。
No changes detected in app 'app_b'
我从这个 ans 开始尝试,并评论 app_label = 'app_a'
。现在迁移后它会检测到更改并创建迁移文件。
然后我执行python manage.py migrate
命令,它不断要求删除原来的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
如何禁止此通知?我如何告诉 django 迁移这个 table 存在于不同的应用程序中?
在我使用 db_table
和 app_label
将我的 table 从 app_a
移动到其他 app_b
之后。
如果我 运行 迁移仅用于 app_a
,则迁移工作正常。
python manage.py makemigrations app_a
此命令 运行 迁移 app_b