0

我正在尝试将 mongodb 集成到使用 sqllite 的现有项目中。

这是我在 settings.py 中添加的用于替换 sqllite 的 mongodb 更改。

import mongoengine
DATABASES = {
    'default': {
        'ENGINE': 'djongo',
    },
}

SESSION_ENGINE = 'mongoengine.django.sessions'

#_MONGODB_USER = 'db_user'
#_MONGODB_PASSWD = 'db_pa'
_MONGODB_HOST = '127.0.0.1'
_MONGODB_NAME = 'adas_cvat'
_MONGODB_DATABASE_HOST = 'mongodb://%s/%s' % (_MONGODB_HOST, _MONGODB_NAME)
mongoengine.connect(_MONGODB_NAME, host=_MONGODB_DATABASE_HOST)

AUTHENTICATION_BACKENDS = (
    'mongoengine.django.auth.MongoEngineBackend',
)

我的版本是

Django==3.1.13
sqlparse==0.2.4
djongo==1.3.6

这是makemigrationsmigrate命令的输出

KOREAN-M-91FL:cvat-backend korean$ python manage.py makemigrations
System check identified some issues:

WARNINGS:
?: (urls.W005) URL namespace 'v1' isn't unique. You may not be able to reverse all URLs in this namespace
No changes detected
(sri) KOREAN-M-91FL:cvat-backend korean$ python manage.py migrate
System check identified some issues:

WARNINGS:
?: (urls.W005) URL namespace 'v1' isn't unique. You may not be able to reverse all URLs in this namespace
Operations to perform:
  Apply all migrations: account, admin, auth, authtoken, contenttypes, dataset_repo, engine, sessions, sites, socialaccount
Running migrations:
  Applying engine.0001_release_v0_1_0...This version of djongo does not support "column type validation" fully. Visit https://nesdis.github.io/djongo/support/

This version of djongo does not support "schema validation using NOT NULL" fully. Visit https://nesdis.github.io/djongo/support/

WARNING - 2021-08-30 12:59:41,978 - query - Not implemented alter command for SQL ALTER TABLE "engine_labeledbox" ALTER COLUMN "id" TYPE long
Traceback (most recent call last):
  File "/Users/korean/cvat-backend/sri/lib/python3.8/site-packages/djongo/cursor.py", line 51, in execute
    self.result = Query(
  File "/Users/korean/cvat-backend/sri/lib/python3.8/site-packages/djongo/sql2mongo/query.py", line 784, in __init__
    self._query = self.parse()
  File "/Users/korean/cvat-backend/sri/lib/python3.8/site-packages/djongo/sql2mongo/query.py", line 876, in parse
    raise e
  File "/Users/korean/cvat-backend/sri/lib/python3.8/site-packages/djongo/sql2mongo/query.py", line 857, in parse
    return handler(self, statement)
  File "/Users/korean/cvat-backend/sri/lib/python3.8/site-packages/djongo/sql2mongo/query.py", line 889, in _alter
    query = AlterQuery(self.db, self.connection_properties, sm, self._params)
  File "/Users/korean/cvat-backend/sri/lib/python3.8/site-packages/djongo/sql2mongo/query.py", line 425, in __init__
    super().__init__(*args)
  File "/Users/korean/cvat-backend/sri/lib/python3.8/site-packages/djongo/sql2mongo/query.py", line 84, in __init__
    super().__init__(*args)
  File "/Users/korean/cvat-backend/sri/lib/python3.8/site-packages/djongo/sql2mongo/query.py", line 62, in __init__
    self.parse()
  File "/Users/korean/cvat-backend/sri/lib/python3.8/site-packages/djongo/sql2mongo/query.py", line 441, in parse
    self._alter(statement)
  File "/Users/korean/cvat-backend/sri/lib/python3.8/site-packages/djongo/sql2mongo/query.py", line 500, in _alter
    raise SQLDecodeError(f'Unknown token: {tok}')
djongo.exceptions.SQLDecodeError: 

        Keyword: Unknown token: TYPE
        Sub SQL: None
        FAILED SQL: ('ALTER TABLE "engine_labeledbox" ALTER COLUMN "id" TYPE long',)
        Params: ([],)
        Version: 1.3.6

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/korean/cvat-backend/sri/lib/python3.8/site-packages/django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
  File "/Users/korean/cvat-backend/sri/lib/python3.8/site-packages/djongo/cursor.py", line 59, in execute
    raise db_exe from e
djongo.database.DatabaseError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "manage.py", line 21, in <module>
    execute_from_command_line(sys.argv)
  File "/Users/korean/cvat-backend/sri/lib/python3.8/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
    utility.execute()
  File "/Users/korean/cvat-backend/sri/lib/python3.8/site-packages/django/core/management/__init__.py", line 395, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Users/korean/cvat-backend/sri/lib/python3.8/site-packages/django/core/management/base.py", line 330, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/Users/korean/cvat-backend/sri/lib/python3.8/site-packages/django/core/management/base.py", line 371, in execute
    output = self.handle(*args, **options)
  File "/Users/korean/cvat-backend/sri/lib/python3.8/site-packages/django/core/management/base.py", line 85, in wrapped
    res = handle_func(*args, **kwargs)
  File "/Users/korean/cvat-backend/sri/lib/python3.8/site-packages/django/core/management/commands/migrate.py", line 243, in handle
    post_migrate_state = executor.migrate(
  File "/Users/korean/cvat-backend/sri/lib/python3.8/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 "/Users/korean/cvat-backend/sri/lib/python3.8/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 "/Users/korean/cvat-backend/sri/lib/python3.8/site-packages/django/db/migrations/executor.py", line 227, in apply_migration
    state = migration.apply(state, schema_editor)
  File "/Users/korean/cvat-backend/sri/lib/python3.8/site-packages/django/db/migrations/migration.py", line 124, in apply
    operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
  File "/Users/korean/cvat-backend/sri/lib/python3.8/site-packages/django/db/migrations/operations/fields.py", line 236, in database_forwards
    schema_editor.alter_field(from_model, from_field, to_field)
  File "/Users/korean/cvat-backend/sri/lib/python3.8/site-packages/django/db/backends/base/schema.py", line 571, in alter_field
    self._alter_field(model, old_field, new_field, old_type, new_type,
  File "/Users/korean/cvat-backend/sri/lib/python3.8/site-packages/django/db/backends/base/schema.py", line 721, in _alter_field
    self.execute(
  File "/Users/korean/cvat-backend/sri/lib/python3.8/site-packages/django/db/backends/base/schema.py", line 142, in execute
    cursor.execute(sql, params)
  File "/Users/korean/cvat-backend/sri/lib/python3.8/site-packages/django/db/backends/utils.py", line 98, in execute
    return super().execute(sql, params)
  File "/Users/korean/cvat-backend/sri/lib/python3.8/site-packages/cacheops/transaction.py", line 93, in execute
    result = self._no_monkey.execute(self, sql, params)
  File "/Users/korean/cvat-backend/sri/lib/python3.8/site-packages/django/db/backends/utils.py", line 66, in execute
    return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
  File "/Users/korean/cvat-backend/sri/lib/python3.8/site-packages/django/db/backends/utils.py", line 75, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "/Users/korean/cvat-backend/sri/lib/python3.8/site-packages/django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
  File "/Users/korean/cvat-backend/sri/lib/python3.8/site-packages/django/db/utils.py", line 90, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/Users/korean/cvat-backend/sri/lib/python3.8/site-packages/django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
  File "/Users/korean/cvat-backend/sri/lib/python3.8/site-packages/djongo/cursor.py", line 59, in execute
    raise db_exe from e
django.db.utils.DatabaseError
(sri) KOREAN-M-91FL:cvat-backend korean$
4

0 回答 0