gpt4 book ai didi

mysql - Django数据库迁移报错: duplicate key

转载 作者:可可西里 更新时间:2023-11-01 07:19:58 24 4
gpt4 key购买 nike

我正在迁移数据库,但我不确定为什么会收到此错误。有谁知道如何解决这一问题?在此之前,我使用 mysql 创建了一个新数据库并授予用户访问权限。我以前有一个工作数据库,但应用程序不工作(将 OSX 升级到 El Capitan)所以我重做了它。我不确定我是否正确创建了新数据库。

> (env)DNab4046b2:VisualGenomeDev gmaister$ python manage.py migrate
> /Users/gmaister/Desktop/VisualGenomeDev/env/lib/python2.7/site-packages/django/test/_doctest.py:59:
> RemovedInDjango18Warning: The django.test._doctest module is
> deprecated; use the doctest module from the Python standard library
> instead. RemovedInDjango18Warning)
>
> /Users/gmaister/Desktop/VisualGenomeDev/env/lib/python2.7/site-packages/django/test/simple.py:27:
> RemovedInDjango18Warning: The django.test.simple module and
> DjangoTestSuiteRunner are deprecated; use
> django.test.runner.DiscoverRunner instead. RemovedInDjango18Warning)
>
> Operations to perform: Synchronize unmigrated apps: lockdown,
> django_extensions, corsheaders, rest_framework Apply all migrations:
> hits, sessions, V6W, djcelery, contenttypes, auth, sites, admin,
> DataAnalysis, RegionAnnotations, common, UserManagement, Sentences,
> Clusters, Evaluation, Canonicalization Synchronizing apps without
> migrations: Creating tables... Installing custom SQL...
> Installing indexes... Running migrations: Applying
> RegionAnnotations.0005_auto_20150716_1133...Traceback (most recent
> call last): File "manage.py", line 10, in <module>
> execute_from_command_line(sys.argv) File "/Users/gmaister/Desktop/VisualGenomeDev/env/lib/python2.7/site-packages/django/core/management/__init__.py",
> line 385, in execute_from_command_line
> utility.execute() File "/Users/gmaister/Desktop/VisualGenomeDev/env/lib/python2.7/site-packages/django/core/management/__init__.py",
> line 377, in execute
> self.fetch_command(subcommand).run_from_argv(self.argv) File "/Users/gmaister/Desktop/VisualGenomeDev/env/lib/python2.7/site-packages/django/core/management/base.py",
> line 288, in run_from_argv
> self.execute(*args, **options.__dict__) File "/Users/gmaister/Desktop/VisualGenomeDev/env/lib/python2.7/site-packages/django/core/management/base.py",
> line 338, in execute
> output = self.handle(*args, **options) File "/Users/gmaister/Desktop/VisualGenomeDev/env/lib/python2.7/site-packages/django/core/management/commands/migrate.py",
> line 160, in handle
> executor.migrate(targets, plan, fake=options.get("fake", False)) File
> "/Users/gmaister/Desktop/VisualGenomeDev/env/lib/python2.7/site-packages/django/db/migrations/executor.py",
> line 63, in migrate
> self.apply_migration(migration, fake=fake) File "/Users/gmaister/Desktop/VisualGenomeDev/env/lib/python2.7/site-packages/django/db/migrations/executor.py",
> line 97, in apply_migration
> migration.apply(project_state, schema_editor) File "/Users/gmaister/Desktop/VisualGenomeDev/env/lib/python2.7/site-packages/django/db/migrations/migration.py",
> line 107, in apply
> operation.database_forwards(self.app_label, schema_editor, project_state, new_state) File
> "/Users/gmaister/Desktop/VisualGenomeDev/env/lib/python2.7/site-packages/django/db/migrations/operations/fields.py",
> line 131, in database_forwards
> schema_editor.alter_field(from_model, from_field, to_field) File "/Users/gmaister/Desktop/VisualGenomeDev/env/lib/python2.7/site-packages/django/db/backends/schema.py",
> line 509, in alter_field
> self._alter_field(model, old_field, new_field, old_type, new_type, old_db_params, new_db_params, strict) File
> "/Users/gmaister/Desktop/VisualGenomeDev/env/lib/python2.7/site-packages/django/db/backends/schema.py",
> line 692, in _alter_field
> "extra": "", File "/Users/gmaister/Desktop/VisualGenomeDev/env/lib/python2.7/site-packages/django/db/backends/schema.py",
> line 98, in execute
> cursor.execute(sql, params) File "/Users/gmaister/Desktop/VisualGenomeDev/env/lib/python2.7/site-packages/django/db/backends/utils.py",
> line 81, in execute
> return super(CursorDebugWrapper, self).execute(sql, params) File "/Users/gmaister/Desktop/VisualGenomeDev/env/lib/python2.7/site-packages/django/db/backends/utils.py",
> line 65, in execute
> return self.cursor.execute(sql, params) File "/Users/gmaister/Desktop/VisualGenomeDev/env/lib/python2.7/site-packages/django/db/utils.py",
> line 94, in __exit__
> six.reraise(dj_exc_type, dj_exc_value, traceback) File "/Users/gmaister/Desktop/VisualGenomeDev/env/lib/python2.7/site-packages/django/db/backends/utils.py",
> line 65, in execute
> return self.cursor.execute(sql, params) File "/Users/gmaister/Desktop/VisualGenomeDev/env/lib/python2.7/site-packages/django/db/backends/mysql/base.py",
> line 128, in execute
> return self.cursor.execute(query, args) File "/Library/Python/2.7/site-packages/MySQLdb/cursors.py", line 205, in
> execute
> self.errorhandler(self, exc, value) File "/Library/Python/2.7/site-packages/MySQLdb/connections.py", line 36,
> in defaulterrorhandler
> raise errorclass, errorvalue django.db.utils.OperationalError: (1061, "Duplicate key name
> 'RegionAnnotations_regionannotation_phrase_ffbaf771d98f6cc_uniq'")

最佳答案

我刚刚遇到了这个错误,我能够通过使用这些 SQL 命令删除错误中指定的索引来解决它:

mysql> DROP INDEX [index_name] ON [table_name];

所以在你的情况下:

mysql> DROP INDEX RegionAnnotations_regionannotation_phrase_ffbaf771d98f6cc_uniq ON RegionAnnotations_regionannotation;

关于mysql - Django数据库迁移报错: duplicate key,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34598177/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com