将详细名称添加到外键字段时,django 1.7迁移错误

阿玛·阿赫塔尔(Ammar Akhtar)

我在架构中的一系列FK字段中添加了一些冗长的名称(一直到相关表链),但是在尝试运行时出现此错误

python manage.py migrate

或python manage.py migration --fake

django.db.utils.IntegrityError:重复的键值违反了唯一约束“ django_migrations_pkey”详细信息:键(id)=(10)已存在。

我的数据库中已经有数据了。所有这些都在Windows 7的本地计算机上运行,​​使用本地主机上的postgres。

完整的踪迹如下

C:\Users\aakh\Documents\Gits\testcap>python manage.py migrate
System check identified some issues:

WARNINGS:
?: (1_6.W001) Some project unittests may not execute as expected.
        HINT: Django 1.6 introduced a new default test runner. It looks like this project was generated using Django 1.5 or earlier. You should ensure your tests are all running & behaving as expected. See https://do
cs.djangoproject.com/en/dev/releases/1.6/#new-test-runner for more information.
Operations to perform:
  Apply all migrations: tccore, sessions, admin, sites, auth, contenttypes
Running migrations:
  Applying tccore.0006_auto_20150130_1243...Traceback (most recent call last):
  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 385, in execute_from_command_line
    utility.execute()
  File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 377, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Python27\lib\site-packages\django\core\management\base.py", line 288, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "C:\Python27\lib\site-packages\django\core\management\base.py", line 338, in execute
    output = self.handle(*args, **options)
  File "C:\Python27\lib\site-packages\django\core\management\commands\migrate.py", line 161, in handle
    executor.migrate(targets, plan, fake=options.get("fake", False))
  File "C:\Python27\lib\site-packages\django\db\migrations\executor.py", line 68, in migrate
    self.apply_migration(migration, fake=fake)
  File "C:\Python27\lib\site-packages\django\db\migrations\executor.py", line 108, in apply_migration
    self.recorder.record_applied(migration.app_label, migration.name)
  File "C:\Python27\lib\site-packages\django\db\migrations\recorder.py", line 67, in record_applied
    self.migration_qs.create(app=app, name=name)
  File "C:\Python27\lib\site-packages\django\db\models\query.py", line 372, in create
    obj.save(force_insert=True, using=self.db)
  File "C:\Python27\lib\site-packages\django\db\models\base.py", line 589, in save
    force_update=force_update, update_fields=update_fields)
  File "C:\Python27\lib\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 "C:\Python27\lib\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 "C:\Python27\lib\site-packages\django\db\models\base.py", line 731, in _do_insert
    using=using, raw=raw)
  File "C:\Python27\lib\site-packages\django\db\models\manager.py", line 92, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "C:\Python27\lib\site-packages\django\db\models\query.py", line 921, in _insert
    return query.get_compiler(using=using).execute_sql(return_id)
  File "C:\Python27\lib\site-packages\django\db\models\sql\compiler.py", line 920, in execute_sql
    cursor.execute(sql, params)
  File "C:\Python27\lib\site-packages\django\db\backends\utils.py", line 81, in execute
    return super(CursorDebugWrapper, self).execute(sql, params)
  File "C:\Python27\lib\site-packages\django\db\backends\utils.py", line 65, 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 65, in execute
    return self.cursor.execute(sql, params)
django.db.utils.IntegrityError: duplicate key value violates unique constraint "django_migrations_pkey"
DETAIL:  Key (id)=(10) already exists.
阿玛·阿赫塔尔(Ammar Akhtar)

弄清楚了...当我应该在相关对象的相关字段中添加详细名称时,我正在向ForeignKey添加详细名称

正确的:

class AppReference(BaseModel):
    name = models.CharField(max_length=200, unique=True, verbose_name="App name")

class App(BaseModel):

    app_reference = models.ForeignKey(AppReference)
    version = models.CharField(max_length=10)

不正确:

class AppReference(BaseModel):
    name = models.CharField(max_length=200, unique=True)

class App(BaseModel):

    app_reference = models.ForeignKey(AppReference, verbose_name="App name")
    version = models.CharField(max_length=10)

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

EF Core 1.1-preview1添加迁移错误

来自分类Dev

添加迁移错误

来自分类Dev

Django 迁移错误

来自分类Dev

Laravel 7迁移错误。无法添加外键约束

来自分类Dev

Django 1.7.1的迁移错误

来自分类Dev

Django迁移错误-NodeNotFoundError

来自分类Dev

在实体属性中使用NotMapped属性时,EF7添加迁移错误

来自分类Dev

在我的迁移错误中添加参考

来自分类Dev

Django迁移错误KeyError :(“列表”,“用户”)

来自分类Dev

Django日期时间迁移错误

来自分类Dev

添加外键时 Laravel 迁移错误

来自分类Dev

Django迁移错误名称“ bPath”未定义

来自分类Dev

添加Linkedin身份验证时发生迁移错误

来自分类Dev

在Heroku上部署时的Django 1.7迁移错误

来自分类Dev

Django + django-oauth-toolkit上的迁移错误

来自分类Dev

删除 Streamfield 块时发生 Wagtail 迁移错误

来自分类Dev

Django迁移错误:该列不存在

来自分类Dev

Django mptt数据库迁移错误

来自分类Dev

Django迁移错误无法适应UUID类型

来自分类Dev

使用 django-csvimport 的项目迁移错误

来自分类Dev

为什么将Selected值添加到我的SelectList会导致模型更改/迁移错误?

来自分类Dev

ASP.NET Core RC1到1.0.0的迁移错误

来自分类Dev

Laravel 5.2委托迁移错误,无法添加外键约束

来自分类Dev

使用DeployBot将ruby on rails应用程序部署到DigitaOcean时的迁移错误

来自分类Dev

Django Port从Postgres迁移到MariaDB manage.py迁移错误SQL语法错误1064

来自分类Dev

转换迁移错误:ProvisioningFailedException:名称“ XXX”已被使用。请尝试使用其他名称。

来自分类Dev

实体框架6.1代码首次迁移错误:EntityType'IdentityUserRole'没有定义键

来自分类Dev

laravel 5.4 迁移错误号:150“外键约束的格式不正确”

来自分类Dev

Django 2.0 迁移错误:“django.core.exceptions.AppRegistryNotReady:应用程序尚未加载。”

Related 相关文章

  1. 1

    EF Core 1.1-preview1添加迁移错误

  2. 2

    添加迁移错误

  3. 3

    Django 迁移错误

  4. 4

    Laravel 7迁移错误。无法添加外键约束

  5. 5

    Django 1.7.1的迁移错误

  6. 6

    Django迁移错误-NodeNotFoundError

  7. 7

    在实体属性中使用NotMapped属性时,EF7添加迁移错误

  8. 8

    在我的迁移错误中添加参考

  9. 9

    Django迁移错误KeyError :(“列表”,“用户”)

  10. 10

    Django日期时间迁移错误

  11. 11

    添加外键时 Laravel 迁移错误

  12. 12

    Django迁移错误名称“ bPath”未定义

  13. 13

    添加Linkedin身份验证时发生迁移错误

  14. 14

    在Heroku上部署时的Django 1.7迁移错误

  15. 15

    Django + django-oauth-toolkit上的迁移错误

  16. 16

    删除 Streamfield 块时发生 Wagtail 迁移错误

  17. 17

    Django迁移错误:该列不存在

  18. 18

    Django mptt数据库迁移错误

  19. 19

    Django迁移错误无法适应UUID类型

  20. 20

    使用 django-csvimport 的项目迁移错误

  21. 21

    为什么将Selected值添加到我的SelectList会导致模型更改/迁移错误?

  22. 22

    ASP.NET Core RC1到1.0.0的迁移错误

  23. 23

    Laravel 5.2委托迁移错误,无法添加外键约束

  24. 24

    使用DeployBot将ruby on rails应用程序部署到DigitaOcean时的迁移错误

  25. 25

    Django Port从Postgres迁移到MariaDB manage.py迁移错误SQL语法错误1064

  26. 26

    转换迁移错误:ProvisioningFailedException:名称“ XXX”已被使用。请尝试使用其他名称。

  27. 27

    实体框架6.1代码首次迁移错误:EntityType'IdentityUserRole'没有定义键

  28. 28

    laravel 5.4 迁移错误号:150“外键约束的格式不正确”

  29. 29

    Django 2.0 迁移错误:“django.core.exceptions.AppRegistryNotReady:应用程序尚未加载。”

热门标签

归档