Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix delete model #43

Merged
merged 2 commits into from
Jul 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion README-zh_CN.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,15 @@ Django Comment Migrate
db_table = 'comment_model'
verbose_name = '这是表注释'

4. 执行数据库迁移::
4. 添加app

project/app/settings.py

.. code:: python

DCM_COMMENT_APP=["app"]

5. 执行数据库迁移::

python manage.py makemigrations
python manage.py migrate
Expand All @@ -68,6 +76,7 @@ Django Comment Migrate
DCM_BACKEND={ # 如果自定义了数据的engine,可以使用该配置
"my-engine": "django_comment_migrate.backends.mysql.CommentMigration"
}
DCM_COMMENT_APP=["app"] # 如果不配置则默认生成所有表的注释


Command
Expand Down
11 changes: 10 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,15 @@ Examples
db_table = 'comment_model'
verbose_name = 'It is Comment Table'

4. execute database migrate::
4. add app

project/app/settings.py

.. code:: python

DCM_COMMENT_APP=["app"]

5. execute database migrate::

python manage.py makemigrations
python manage.py migrate
Expand All @@ -68,6 +76,7 @@ In settings.py::
DCM_BACKEND={
"new-engine": "engine.path"
}
DCM_COMMENT_APP=["app"]

Command
-------
Expand Down
1 change: 1 addition & 0 deletions django_comment_migrate/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class DCMConfig:
"DCM_COMMENT_KEY": "help_text",
"DCM_TABLE_COMMENT_KEY": "verbose_name",
"DCM_BACKEND": None,
"DCM_COMMENT_APP": []
}

def __getattr__(self, name):
Expand Down
9 changes: 7 additions & 2 deletions django_comment_migrate/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ def get_migrations_app_models(
migrations: [Migration], apps, using=DEFAULT_DB_ALIAS
) -> set:
models = set()
from django_comment_migrate.config import dcm_config # noqa
dcm_comment_app = dcm_config.DCM_COMMENT_APP
for migration in migrations:
if not isinstance(migration, Migration):
continue
app_label = migration.app_label
if not router.allow_migrate(using, app_label):
if not router.allow_migrate(using, app_label) or app_label not in dcm_comment_app:
continue
operations = getattr(migration, "operations", [])
for operation in operations:
Expand All @@ -35,6 +37,9 @@ def get_migrations_app_models(
)
if model_name is None:
continue
model = apps.get_model(app_label, model_name=model_name)
try:
model = apps.get_model(app_label, model_name=model_name)
except LookupError:
continue
models.add(model)
return models