TencentBlueKing / bk-itsm

ITSM-流程服务管理,通过可自定义设计的流程管理,同时关联蓝鲸智云的基础平台、公共组件,以满足IT服务的管理活动和场景需要。帮助用户规范内部管理流程,并提升管理效率。
MIT License
132 stars 94 forks source link

本地环境搭建,迁移db报错提示iam migrate fail ,需要BK_IAM_SKIP=False吗 #974

Closed txjjjjj closed 1 year ago

txjjjjj commented 1 year ago

case: 本地环境搭建(想做二次开发) 问题: 迁移失败 版本: 2.6.1.395 环境: centos7 python3.6.12(pyenv) 社区版: v6 单机部署(本地复用的部署完后的bk_itsm的app_code/secret)

(bk-itsm-2.6.1.395) [root@c7 pycharm_project_173]# python manage.py migrate
You are using Python 3.6. This version does not support timestamps with nanosecond precision and the OpenTelemetry SDK will use millisecond precision instead. Please refer to PEP 564 for more information. Please upgrade to Python 3.7 or newer to use nanosecond precision.
This is the first deployment
发现非2.6.0 之前的升级版本,已跳过修复
init redis settings
autodiscover rpc: rpc.components
autodiscover trigger: action.components
init api public key
init api public success
System check identified some issues:

WARNINGS:
?: (mysql.W002) MySQL Strict Mode is not set for database connection 'default'
    HINT: MySQL's Strict Mode fixes many data integrity problems in MySQL, such as data truncation upon insertion, by escalating warnings into errors. It is strongly recommended you activate it. See: https://docs.djangoproject.com/en/3.2/ref/databases/#mysql-sql-mode
ticket.SignTask.is_passed: (fields.W903) NullBooleanField is deprecated. Support for it (except in historical migrations) will be removed in Django 4.0.
    HINT: Use BooleanField(null=True) instead.
ticket.TicketRemark.ticket_id: (fields.W122) 'max_length' is ignored when used with IntegerField.
    HINT: Remove 'max_length' from field
ticket.TicketRemark.update_log: (fields.E010) JSONField default should be a callable instead of an instance so that it's not shared between all field instances.
    HINT: Use a callable instead, e.g., use `dict` instead of `{}`.
ticket.TicketRemark.users: (fields.E010) JSONField default should be a callable instead of an instance so that it's not shared between all field instances.
    HINT: Use a callable instead, e.g., use `dict` instead of `{}`.
workflow.Workflow.is_task_needed: (fields.W903) NullBooleanField is deprecated. Support for it (except in historical migrations) will be removed in Django 4.0.
    HINT: Use BooleanField(null=True) instead.
workflow.WorkflowVersion.is_task_needed: (fields.W903) NullBooleanField is deprecated. Support for it (except in historical migrations) will be removed in Django 4.0.
    HINT: Use BooleanField(null=True) instead.
Operations to perform:
  Apply all migrations: account, admin, apigw, auth, auth_iam, component_framework, contenttypes, data_migration, django_celery_beat, django_celery_results, django_nyt, django_signal_valve, engine, iadmin, iam_migration, log, pipeline, postman, project, role, service, sessions, sites, sla, sla_engine, task, thumbnail, ticket, ticket_status, trigger, variable_framework, weixin_core, workflow
Running migrations:
  Applying contenttypes.0001_initial... OK
  Applying contenttypes.0002_remove_content_type_name... OK
  Applying auth.0001_initial... OK
  Applying auth.0002_alter_permission_name_max_length... OK
  Applying auth.0003_alter_user_email_max_length... OK
  Applying auth.0004_alter_user_username_opts... OK
  Applying auth.0005_alter_user_last_login_null... OK
  Applying auth.0006_require_contenttypes_0002... OK
  Applying auth.0007_alter_validators_add_error_messages... OK
  Applying auth.0008_alter_user_username_max_length... OK
  Applying account.0001_initial... OK
  Applying account.0002_init_superuser... OK
  Applying account.0003_verifyinfo... OK
  Applying account.0004_create_cache_table... OK
  Applying admin.0001_initial... OK
  Applying admin.0002_logentry_remove_auto_add... OK
  Applying admin.0003_logentry_add_action_flag_choices... OK
  Applying apigw.0001_initial... OK
  Applying auth.0009_alter_user_last_name_max_length... OK
  Applying auth.0010_alter_group_name_max_length... OK
  Applying auth.0011_update_proxy_permissions... OK
  Applying auth.0012_alter_user_first_name_max_length... OK
  Applying iam_migration.0001_initial...do migrate
_call_iam_api fail. method: http_get path: /api/v1/model/systems/itsm/query error: not found:system(itsm) not exists
do api_query fail not found:system(itsm) not exists
_call_iam_api fail. method: http_post path: /api/v1/model/systems error: bad request:Host is required
execute operation [upsert_system] bad request:Host is required fail, error message: id=itsm
Traceback (most recent call last):
  File "manage.py", line 43, in <module>
    execute_from_command_line(sys.argv)
  File "/root/.virtualenvs/bk-itsm-2.6.1.395/lib/python3.6/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
    utility.execute()
  File "/root/.virtualenvs/bk-itsm-2.6.1.395/lib/python3.6/site-packages/django/core/management/__init__.py", line 413, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/root/.virtualenvs/bk-itsm-2.6.1.395/lib/python3.6/site-packages/django/core/management/base.py", line 354, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/root/.virtualenvs/bk-itsm-2.6.1.395/lib/python3.6/site-packages/django/core/management/base.py", line 398, in execute
    output = self.handle(*args, **options)
  File "/root/.virtualenvs/bk-itsm-2.6.1.395/lib/python3.6/site-packages/django/core/management/base.py", line 89, in wrapped
    res = handle_func(*args, **kwargs)
  File "/root/.virtualenvs/bk-itsm-2.6.1.395/lib/python3.6/site-packages/django/core/management/commands/migrate.py", line 246, in handle
    fake_initial=fake_initial,
  File "/root/.virtualenvs/bk-itsm-2.6.1.395/lib/python3.6/site-packages/django/db/migrations/executor.py", line 117, in migrate
    state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
  File "/root/.virtualenvs/bk-itsm-2.6.1.395/lib/python3.6/site-packages/django/db/migrations/executor.py", line 147, in _migrate_all_forwards
    state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
  File "/root/.virtualenvs/bk-itsm-2.6.1.395/lib/python3.6/site-packages/django/db/migrations/executor.py", line 227, in apply_migration
    state = migration.apply(state, schema_editor)
  File "/root/.virtualenvs/bk-itsm-2.6.1.395/lib/python3.6/site-packages/django/db/migrations/migration.py", line 123, in apply
    operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
  File "/root/.virtualenvs/bk-itsm-2.6.1.395/lib/python3.6/site-packages/django/db/migrations/operations/special.py", line 190, in database_forwards
    self.code(from_state.apps, schema_editor)
  File "/tmp/pycharm_project_173/iam/contrib/iam_migration/migrations/0001_initial.py", line 16, in forward_func
    migrator.migrate()
  File "/tmp/pycharm_project_173/iam/contrib/iam_migration/migrator.py", line 65, in migrate
    raise exceptions.MigrationFailError("iam migrate fail")
iam.contrib.iam_migration.exceptions.MigrationFailError: iam migrate fail
txjjjjj commented 1 year ago

https://github.com/TencentBlueKing/bk-itsm/blob/master/scripts/workflows/local_settings.py#L51

本地开发BK_IAM_SKIP得重置为false才能迁移成功, 建议把这几行写入 dev_deployment.md

hanshuaikang commented 1 year ago

好的,感谢