Python Django migrate在添加新字段或修改现有字段后失败,但我没有';我不想删除我的数据库列

Python Django migrate在添加新字段或修改现有字段后失败,但我没有';我不想删除我的数据库列,python,django,django-models,django-migrations,Python,Django,Django Models,Django Migrations,我不得不面对一些困扰我的事情,让我怀疑我是否真的理解了django 首先,我改变了模型中的一点: article_country = models.ManyToManyField(Country, verbose_name=_('Country of the article'), blank=True, null=True, related_name='region

我不得不面对一些困扰我的事情,让我怀疑我是否真的理解了django

首先,我改变了模型中的一点:

article_country = models.ManyToManyField(Country, verbose_name=_('Country of the article'),
                                 blank=True, null=True,
                                 related_name='regions_press_article')
相关名称为:
related\u name='country\u press\u article')

当我尝试迁移时,我有一个可爱的错误:

Unapplying djangocms_press.0002_auto_20160229_1136...Traceback (most recent call last):
File "./manage.py", line 11, in <module>
execute_from_command_line(sys.argv)
File "/var/www/webapps/lib/python3.4/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
File "/var/www/webapps/lib/python3.4/site-packages/django/core/management/__init__.py", line 377, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/var/www/webapps/lib/python3.4/site-packages/django/core/management/base.py", line 288, in run_from_argv
self.execute(*args, **options.__dict__)
File "/var/www/webapps/lib/python3.4/site-packages/raven/contrib/django/management/__init__.py", line 41, in new_execute
return original_func(self, *args, **kwargs)
File "/var/www/webapps/lib/python3.4/site-packages/django/core/management/base.py", line 338, in execute
output = self.handle(*args, **options)
File "/var/www/webapps/lib/python3.4/site-packages/django/core/management/commands/migrate.py", line 161, in handle
executor.migrate(targets, plan, fake=options.get("fake", False))
File "/var/www/webapps/lib/python3.4/site-packages/django/db/migrations/executor.py", line 70, in migrate
self.unapply_migration(migration, fake=fake)
File "/var/www/webapps/lib/python3.4/site-packages/django/db/migrations/executor.py", line 122, in unapply_migration
migration.unapply(project_state, schema_editor)
File "/var/www/webapps/lib/python3.4/site-packages/django/db/migrations/migration.py", line 157, in unapply
operation.database_backwards(self.app_label, schema_editor, from_state, to_state)
File "/var/www/webapps/lib/python3.4/site-packages/django/db/migrations/operations/fields.py", line 144, in database_backwards
self.database_forwards(app_label, schema_editor, from_state, to_state)
File "/var/www/webapps/lib/python3.4/site-packages/django/db/migrations/operations/fields.py", line 139, in database_forwards
schema_editor.alter_field(from_model, from_field, to_field)
File "/var/www/webapps/lib/python3.4/site-packages/django/db/backends/schema.py", line 460, in alter_field
return self._alter_many_to_many(model, old_field, new_field, strict)
File "/var/www/webapps/lib/python3.4/site-packages/django/db/backends/schema.py", line 759, in _alter_many_to_many
new_field.rel.through._meta.get_field_by_name(new_field.m2m_reverse_field_name())[0],
File "/var/www/webapps/lib/python3.4/site-packages/django/db/backends/schema.py", line 470, in alter_field
self._alter_field(model, old_field, new_field, old_type, new_type, old_db_params, new_db_params, strict)
File "/var/www/webapps/lib/python3.4/site-packages/django/db/backends/schema.py", line 478, in _alter_field
fk_names = self._constraint_names(model, [old_field.column], foreign_key=True)
File "/var/www/webapps/lib/python3.4/site-packages/django/db/backends/schema.py", line 886, in _constraint_names
constraints = self.connection.introspection.get_constraints(cursor, model._meta.db_table)
File "/var/www/webapps/lib/python3.4/site-packages/django/db/backends/postgresql_psycopg2/introspection.py", line 149, in get_constraints
"foreign_key": tuple(used_cols[0].split(".", 1)) if kind.lower() == "foreign key" else None,
 IndexError: list index out of range
(我声明撤消国家/地区更改并删除与之链接的迁移文件)

发生了什么事?使用migrate命令显示相同的错误

为什么在模型中进行如此小的修改会如此复杂?如何解决它?

哦,顺便说一下,我已经通过执行./manage.py migrate myapp zero解决了这类问题


但这次我不想删除我的app DB

您会遇到相同的错误,因为一旦创建了迁移,以后的任何其他迁移都将仅在迁移完成后执行(基于迁移编号)。抱歉,事实上,我没有明确说明我删除了更改,删除了第一次迁移(关于地区到国家),然后创建了其他字段。我编辑了它。
related\u name
是Django使用的一个名称,我认为它不适用于数据库。您使用的是哪个
gettext
函数?懒惰还是仅仅
ugettext()
?关于迁移,您需要从数据库和app>migration文件夹内的文件中删除。谢谢您的回答Ev,我使用ugettext\u
global_name = models.CharField(_('Global Name'), max_length=310, null=True)