重复键值违反唯一约束“wagtailcore_page_path_key”DETAIL:键(路径)=(0001)已存在

时间:2017-04-25 13:34:52

标签: python django postgresql migration wagtail

我正在开发一个由其他人基于Django和wagtail开发的系统。我设法将数据导入postgresql但我相信并非所有内容都已导入,因为我在尝试迁移数据时遇到错误。这是我得到的错误:

# python manage.py migrate
/root/Desktop/Projects/sautimtaani/sautivenv/local/lib/python2.7/site-packages/treebeard/mp_tree.py:102: RemovedInDjango18Warning: `MP_NodeManager.get_query_set` method should be renamed `get_queryset`.
  class MP_NodeManager(models.Manager):

 /root/Desktop/Projects/sautimtaani/sautivenv/local/lib/python2.7/site-packages/django/forms/widgets.py:143: RemovedInDjango18Warning: `TaskMonitor.queryset` method should be renamed `get_queryset`.
  .__new__(mcs, name, bases, attrs))

 /root/Desktop/Projects/sautimtaani/sautivenv/local/lib/python2.7/site-packages/djcelery/loaders.py:192: UserWarning: Autodiscover: Error importing sauti_mtaani.apps.core.app.CoreConfig.tasks: ImportError('No module named CoreConfig',)
  app, related_name, exc,

 /root/Desktop/Projects/sautimtaani/sautivenv/local/lib/python2.7/site-packages/djcelery/loaders.py:192: UserWarning: Autodiscover: Error importing sauti_mtaani.apps.sauti_mtaani_main.app.SautiMtaaniMainConfig.tasks: ImportError('No module named SautiMtaaniMainConfig',)
  app, related_name, exc,

/root/Desktop/Projects/sautimtaani/sautivenv/local/lib/python2.7/site-packages/djcelery/admin.py:256: RemovedInDjango18Warning: Creating a ModelForm without either the 'fields' attribute or the 'exclude' attribute is deprecated - form PeriodicTaskForm needs updating
  class PeriodicTaskForm(forms.ModelForm):

/root/Desktop/Projects/sautimtaani/sautivenv/local/lib/python2.7/site-packages/django/forms/widgets.py:143: RemovedInDjango18Warning: `PeriodicTaskAdmin.queryset` method should be renamed `get_queryset`.
  .__new__(mcs, name, bases, attrs))

 Operations to perform:
 Synchronize unmigrated apps: wagtailsnippets, compressor, modelcluster, djcelery, django_extensions
 Apply all migrations: core, wagtailusers, wagtailembeds, wagtailadmin, sauti_mtaani_main, sessions, admin, polls, auth, wagtailcore, contenttypes, wagtaildocs, taggit, wagtailsearch, wagtailforms, wagtailredirects, wagtailimages
 Synchronizing apps without migrations:
    Creating tables...
    Installing custom SQL...
    Installing indexes...
 Running migrations:
 Applying wagtailcore.0002_initial_data...Traceback (most recent call last):
 File "manage.py", line 10, in <module>
   execute_from_command_line(sys.argv)
 File 
  "/root/Desktop/Projects/sautimtaani/sautivenv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
 File 

  "/root/Desktop/Projects/sautimtaani/sautivenv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 377, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
 File 
  "/root/Desktop/Projects/sautimtaani/sautivenv/local/lib/python2.7/site-packages/django/core/management/base.py", line 288, in run_from_argv
    self.execute(*args, **options.__dict__)
 File 
 "/root/Desktop/Projects/sautimtaani/sautivenv/local/lib/python2.7/site-packages/django/core/management/base.py", line 338, in execute
     output = self.handle(*args, **options)
 File 
"/root/Desktop/Projects/sautimtaani/sautivenv/local/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 161, in handle
   executor.migrate(targets, plan, fake=options.get("fake", False))
 File 
"/root/Desktop/Projects/sautimtaani/sautivenv/local/lib/python2.7/site-packages/django/db/migrations/executor.py", line 68, in migrate
      self.apply_migration(migration, fake=fake)
  File 
"/root/Desktop/Projects/sautimtaani/sautivenv/local/lib/python2.7/site-packages/django/db/migrations/executor.py", line 102, in apply_migration
    migration.apply(project_state, schema_editor)
   File 
  "/root/Desktop/Projects/sautimtaani/sautivenv/local/lib/python2.7/site-packages/django/db/migrations/migration.py", line 108, in apply
    operation.database_forwards(self.app_label, schema_editor, project_state, new_state)
 File 
"/root/Desktop/Projects/sautimtaani/sautivenv/local/lib/python2.7/site-packages/django/db/migrations/operations/special.py", line 117, in database_forwards
   self.code(from_state.render(), schema_editor)
 File 
"/root/Desktop/Projects/sautimtaani/sautivenv/local/lib/python2.7/site-packages/wagtail/wagtailcore/migrations/0002_initial_data.py", line 29, in initial_data
   url_path='/',
  File 
"/root/Desktop/Projects/sautimtaani/sautivenv/local/lib/python2.7/site-packages/django/db/models/manager.py", line 92, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File 
"/root/Desktop/Projects/sautimtaani/sautivenv/local/lib/python2.7/site-packages/django/db/models/query.py", line 372, in create
    obj.save(force_insert=True, using=self.db)
  File 
"/root/Desktop/Projects/sautimtaani/sautivenv/local/lib/python2.7/site-packages/django/db/models/base.py", line 589, in save
force_update=force_update, update_fields=update_fields)
  File 
"/root/Desktop/Projects/sautimtaani/sautivenv/local/lib/python2.7/site-packages/django/db/models/base.py", line 617, in save_base
updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)
  File 
"/root/Desktop/Projects/sautimtaani/sautivenv/local/lib/python2.7/site-packages/django/db/models/base.py", line 698, in _save_table
result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)
  File 
"/root/Desktop/Projects/sautimtaani/sautivenv/local/lib/python2.7/site-packages/django/db/models/base.py", line 731, in _do_insert
using=using, raw=raw)
  File 
"/root/Desktop/Projects/sautimtaani/sautivenv/local/lib/python2.7/site-packages/django/db/models/manager.py", line 92, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
  File 
"/root/Desktop/Projects/sautimtaani/sautivenv/local/lib/python2.7/site-packages/django/db/models/query.py", line 921, in _insert
return query.get_compiler(using=using).execute_sql(return_id)
  File 
"/root/Desktop/Projects/sautimtaani/sautivenv/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 920, in execute_sql
cursor.execute(sql, params)
  File 
"/root/Desktop/Projects/sautimtaani/sautivenv/local/lib/python2.7/site-packages/django/db/backends/utils.py", line 81, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
  File 
"/root/Desktop/Projects/sautimtaani/sautivenv/local/lib/python2.7/site-packages/django/db/backends/utils.py", line 65, in execute
return self.cursor.execute(sql, params)
  File 
"/root/Desktop/Projects/sautimtaani/sautivenv/local/lib/python2.7/site-packages/django/db/utils.py", line 94, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
  File 
"/root/Desktop/Projects/sautimtaani/sautivenv/local/lib/python2.7/site-packages/django/db/backends/utils.py", line 65, in execute
return self.cursor.execute(sql, params)
django.db.utils.IntegrityError: duplicate key value violates unique constraint "wagtailcore_page_path_key"
DETAIL:  Key (path)=(0001) already exists.

我已经在网上到处寻找解决方案,但到目前为止还没有任何帮助。请帮助我,如果你能找到解决方案,请记住我没有在django上发展太多。

以下是我尝试从wagtail管理部分创建其中一个wagtail页面时所获得的更新:

Environment:


Request Method: GET
Request URL: http://127.0.0.1:8000/wadmin/pages/new/sauti_mtaani_main/bloglistingtitleextrapage/3/

Django Version: 1.7.5
Python Version: 2.7.12
Installed Applications:
('django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'sauti_mtaani.apps.core.app.CoreConfig',
 'compressor',
 'taggit',
 'modelcluster',
 'django.contrib.admin',
 'wagtail.wagtailcore',
 'wagtail.wagtailadmin',
 'wagtail.wagtaildocs',
 'wagtail.wagtailsnippets',
 'wagtail.wagtailusers',
 'wagtail.wagtailimages',
 'wagtail.wagtailembeds',
 'wagtail.wagtailsearch',
 'wagtail.wagtailredirects',
 'wagtail.wagtailforms',
 'wagtail.wagtailsites',
 'djcelery',
 'sauti_mtaani.apps.sauti_mtaani_main.app.SautiMtaaniMainConfig',
 'sauti_mtaani.apps.polls',
 'dbbackup',
 'django.contrib.humanize',
 'django_extensions')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware',
 'wagtail.wagtailcore.middleware.SiteMiddleware',
 'wagtail.wagtailredirects.middleware.RedirectMiddleware')


Traceback:
File "/root/Desktop/Projects/sautimtaani/sautivenv/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
  111.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/root/Desktop/Projects/sautimtaani/sautivenv/local/lib/python2.7/site-packages/django/contrib/auth/decorators.py" in _wrapped_view
  21.                 return view_func(request, *args, **kwargs)
File "/root/Desktop/Projects/sautimtaani/sautivenv/local/lib/python2.7/site-packages/wagtail/wagtailadmin/views/pages.py" in create
  237.         edit_handler = edit_handler_class(instance=page, form=form)
File "/root/Desktop/Projects/sautimtaani/sautivenv/local/lib/python2.7/site-packages/wagtail/wagtailadmin/edit_handlers.py" in __init__
  298.             for handler_class in self.__class__.children
File "/root/Desktop/Projects/sautimtaani/sautivenv/local/lib/python2.7/site-packages/wagtail/wagtailadmin/edit_handlers.py" in __init__
  298.             for handler_class in self.__class__.children
File "/root/Desktop/Projects/sautimtaani/sautivenv/local/lib/python2.7/site-packages/wagtail/wagtailadmin/edit_handlers.py" in __init__
  366.         self.bound_field = self.form[self.field_name]
File "/root/Desktop/Projects/sautimtaani/sautivenv/local/lib/python2.7/site-packages/django/forms/forms.py" in __getitem__
  147.                 "Key %r not found in '%s'" % (name, self.__class__.__name__))

Exception Type: KeyError at /wadmin/pages/new/sauti_mtaani_main/bloglistingtitleextrapage/3/
Exception Value: u"Key 'content' not found in 'BlogListingTitleExtraPageForm'"

1 个答案:

答案 0 :(得分:0)

我希望您尝试恢复相同主键的数据。 只需删除已存在数据的primary_key,然后尝试再次恢复数据库。

希望它能帮到你