이 질문은 here 전에 물어 보았습니다.Django '키 (필드) =() 중복되었습니다'
저는 Django/Wagtail 프로젝트에서 작업 중입니다. 어떤 시점에서 모델을 수정하고 일부 필드를 추가해야했습니다.
실수로 나는 새로운 분야에 대한 진정한 고유의 플래그를 = 포함되어 있습니다. 이 방법 : 마이그레이션을하고 마이그레이션 할 때title = models.CharField(max_length=100, unique=True, blank=True, null=True, verbose_name=_('Category Title'))
, 그것은이 문제를 외쳤다 : 내가 실수를 깨달았 그리고
는 = true라고 독특한 제거하고 이런 식으로 왼쪽 :
마이그레이션을 수행하고 다시 문제가 사라질 것으로 예상됩니다. 그러나 나는 같은 문제가있다.
어떻게 해결할 수 있습니까?
class Migration(migrations.Migration):
dependencies = [
('distributed', '0029_remove_blogcategory_title'),
]
operations = [
migrations.AddField(
model_name='blogcategory',
name='title',
field=models.CharField(blank=True, max_length=100, null=True, verbose_name='Category Title'),
),
]
그리고 이것은 추적입니다 :
이 지난 마이그레이션입니다
Microsoft Windows [Versión 6.1.7600]
Copyright (c) 2009 Microsoft Corporation. Reservados todos los derechos.
C:\Windows\system32>cd C:/
C:\>cd distributed
C:\distributed>cd distributed
C:\distributed\distributed>python manage.py runserver
Performing system checks...
System check identified no issues (0 silenced).
You have 6 unapplied migration(s). Your project may not work properly until you
apply the migrations for app(s): distributed.
Run 'python manage.py migrate' to apply them.
April 26, 2017 - 12:40:45
Django version 1.10.7, using settings 'genesis.settings.dev'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
^C
C:\distributed\distributed>python manage.py migrate
Operations to perform:
Apply all migrations: admin, auth, contenttypes, distributed, otp_static, otp_
totp, otp_yubikey, sessions, sites, taggit, two_factor, wagtailadmin, wagtailcor
e, wagtaildocs, wagtailembeds, wagtailforms, wagtailimages, wagtailredirects, wa
gtailsearch, wagtailusers
Running migrations:
Applying distributed.0025_auto_20170425_1827...Traceback (most recent call las
t):
File "manage.py", line 11, in <module>
execute_from_command_line(sys.argv)
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line
367, in execute_from_command_line
utility.execute()
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line
359, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Python27\lib\site-packages\django\core\management\base.py", line 294,
in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Python27\lib\site-packages\django\core\management\base.py", line 345,
in execute
output = self.handle(*args, **options)
File "C:\Python27\lib\site-packages\django\core\management\commands\migrate.py
", line 204, in handle
fake_initial=fake_initial,
File "C:\Python27\lib\site-packages\django\db\migrations\executor.py", line 11
5, in migrate
state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_i
nitial=fake_initial)
File "C:\Python27\lib\site-packages\django\db\migrations\executor.py", line 14
5, in _migrate_all_forwards
state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_
initial)
File "C:\Python27\lib\site-packages\django\db\migrations\executor.py", line 24
4, in apply_migration
state = migration.apply(state, schema_editor)
File "C:\Python27\lib\site-packages\django\db\migrations\migration.py", line 1
29, in apply
operation.database_forwards(self.app_label, schema_editor, old_state, projec
t_state)
File "C:\Python27\lib\site-packages\django\db\migrations\operations\fields.py"
, line 84, in database_forwards
field,
File "C:\Python27\lib\site-packages\django\db\backends\postgresql\schema.py",
line 21, in add_field
super(DatabaseSchemaEditor, self).add_field(model, field)
File "C:\Python27\lib\site-packages\django\db\backends\base\schema.py", line 4
09, in add_field
self.execute(sql, params)
File "C:\Python27\lib\site-packages\django\db\backends\base\schema.py", line 1
12, in execute
cursor.execute(sql, params)
File "C:\Python27\lib\site-packages\django\db\backends\utils.py", line 79, in
execute
return super(CursorDebugWrapper, self).execute(sql, params)
File "C:\Python27\lib\site-packages\cachalot\monkey_patch.py", line 111, in in
ner
out = original(cursor, sql, *args, **kwargs)
File "C:\Python27\lib\site-packages\django\db\backends\utils.py", line 64, in
execute
return self.cursor.execute(sql, params)
File "C:\Python27\lib\site-packages\django\db\utils.py", line 94, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "C:\Python27\lib\site-packages\django\db\backends\utils.py", line 64, in
execute
return self.cursor.execute(sql, params)
django.db.utils.IntegrityError: could not create unique index "distributed_blogc
ategory_title_key"
DETAIL: Key (title)=() is duplicated.
C:\distributed\distributed>
그냥 추가했습니다 –
추적 결과는'distributed.0025_auto_20170425_1827'에서 오류가 발생하고 있음을 알려주고 있습니다. 'python manage.py showmigrations distributed'의 결과는 무엇입니까? – Alasdair
당신 말이 맞아요. 이것은 나의 '신참'이 분명하게 드러나는 곳입니다. 새로운 마이그레이션이 오래된 마이그레이션을 "덮어 썼다"고 생각했습니다. 그렇다면 오류를 일으키는 마이그레이션까지 마이그레이션을 삭제하고 make migration을 다시 실행해야합니까? –