У меня есть простая модель, которая определяется как (sample_app / models.py):
class ABC(models.Model):
field1 = models.CharField(max_length=255, db_index=True)
field2 = models.CharField(max_length=255)
, затем я запускаю
python3 manage.py makemigration sample_app
Миграция создана. Выполнение
python3 manage.py migrate sample_app
Миграция выполнена успешно.
Я вошел в оболочку mon go и проверил индексы:
db.collectino_name.getIndexes()
Output-->
[
{
"v" : 2,
"key" : {
"_id" : 1
},
"name" : "_id_",
"ns" : "some_info"
},
{
"v" : 2,
"unique" : true,
"key" : {
"id" : 1
},
"name" : "__primary_key__",
"ns" : "some_info"
},
{
"v" : 2,
"key" : {
"field1" : 1
},
"name" : "some_info_field1_a59e0e95",
"ns" : "some_info"
}
]
Итак, индекс создан , Отлично. Теперь я хочу удалить индексы. Я изменил свой model.py, чтобы он выглядел следующим образом.
class ABC(models.Model):
field1 = models.CharField(max_length=255)
field2 = models.CharField(max_length=255)
Затем успешно запустите makemigration и во время миграции произошла ошибка.
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "venv/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command
_line
utility.execute()
File "venv/lib/python3.6/site-packages/django/core/management/__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "venv/lib/python3.6/site-packages/django/core/management/base.py", line 316, in run_from_argv
self.execute(*args, **cmd_options)
File "venv/lib/python3.6/site-packages/django/core/management/base.py", line 353, in execute
output = self.handle(*args, **options)
File "venv/lib/python3.6/site-packages/django/core/management/base.py", line 83, in wrapped
res = handle_func(*args, **kwargs)
File "venv/lib/python3.6/site-packages/django/core/management/commands/migrate.py", line 203, in handle
fake_initial=fake_initial,
File "venv/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 "venv/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 "venv/lib/python3.6/site-packages/django/db/migrations/executor.py", line 244, in apply_migration
state = migration.apply(state, schema_editor)
File "venv/lib/python3.6/site-packages/django/db/migrations/migration.py", line 124, in apply
operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
File "venv/lib/python3.6/site-packages/django/db/migrations/operations/fields.py", line 216, in database_forw
ards
schema_editor.alter_field(from_model, from_field, to_field)
File "venv/lib/python3.6/site-packages/django/db/backends/base/schema.py", line 523, in alter_field
old_db_params, new_db_params, strict)
File "venv/lib/python3.6/site-packages/django/db/backends/base/schema.py", line 586, in _alter_field
index_names = self._constraint_names(model, [old_field.column], index=True, type_=Index.suffix)
File "venv/lib/python3.6/site-packages/django/db/backends/base/schema.py", line 1047, in _constraint_names
if type_ is not None and infodict['type'] != type_:
KeyError: 'type'
Невозможно выполнить миграцию :(. Здесь я могу получить значение type_ (т.е. idx), но не infodict ['type']
Но если я удалите индекс из mongoshell (используя dropIndex), после чего я смогу выполнить миграцию.
Итак, любая идея, в чем проблема?
Вот требование.txt
pymongo==3.7.2
djongo==1.2.31
Django==2.1.7
coreschema==0.0.4
sqlparse==0.2.4
Я также проверил эти ссылки.
https://github.com/jazzband/django-oauth-toolkit/issues/527