【问题标题】:Integrity constraint violation: 1048 Column cannot be null error违反完整性约束:1048 列不能为空错误
【发布时间】:2010-08-09 09:19:18
【问题描述】:

我在 symfony 1.4 和教义 1.2 中遇到了一个奇怪的错误。我的模式似乎很正常。但是每当我执行doctrine:build --all --no-confirmation --and-load 任务时,它就会输出错误SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'default_edition_id' cannot be null。如果我将 default_edition_id 字段的 notnull 设置为 false,它实际上只是 null。谁能帮我解决我可能缺少的东西?

这是我的架构文件(chapter.yml):

Chapter:
  actAs:
    Timestampable: ~
    Versionable:
      versionColumn: version
      className: %CLASS%Version
    SoftDelete: ~
  columns:
    name: string
    chapter_number: { type: integer, notnull: true }
    series_id: { type: integer, notnull: true }
    default_edition_id: { type: integer, notnull: true }
    disabled:
      type: enum
      values: [1, 0]
      default: 0
      notnull: true
  relations:
    DefaultEdition:
      local: default_edition_id
      class: Edition
      foreign: id
      foreignAlias: DefaultChapter
      foreignType: one
      type: one
#      onDelete: CASCADE
    Series:
      local: series_id
      foreign: id
      onDelete: CASCADE
    Editions:
      type: many
      class: Edition
      local: id
      foreign: chapter_id

和我的版本架构(edition.yml):

Edition:
  actAs:
    Timestampable: ~
    Sluggable:
       fields: [name]
    Versionable:
      versionColumn: version
      className: %CLASS%Version
    SoftDelete: ~
  columns:
    name: string
    completed_reads: { type: integer, notnull: true, default: 0}
    views: { type: integer, notnull: true, default: 0 }
    language_id: { type: integer, notnull: true }
    chapter_id: { type: integer, notnull: true }
    disabled:
      type: enum
      values: [1, 0]
      default: 0
      notnull: true
  relations:
    Pages:
      type: many
      class: Page
      local: id
      foreign: edition_id
    Language:
      local: language_id
      foreign: id
      type: one
      onDelete: CASCADE
    Chapter:
      local: chapter_id
      foreign: id
      onDelete: CASCADE

夹具:

Chapter:
  bakuman_chapter:
    Series: bakuman
    chapter_number: 86
    DefaultEdition: edition_1
  bakuman_chapter2:
    Series: bakuman
    DefaultEdition: edition_2
    chapter_number: 90

Edition:
  edition_1:
    name: edition 1
    Chapter: bakuman_chapter
    ScanlationGroup: [group_1, group_2, group_3]
    Language: english
  edition_2:
    name: edition 2
    Chapter: bakuman_chapter2
    ScanlationGroup: [group_4]
    Language: japanese
  edition_2_2:
    name: edition 2_2
    Chapter: bakuman_chapter2
    ScanlationGroup: [group_4, group_2]
    Language: english

【问题讨论】:

    标签: symfony1 doctrine symfony-1.4 doctrine-1.2


    【解决方案1】:

    “如果我将 default_edition_id 字段的 notnull 设置为 false,它实际上只是 null”。在这句话中,“它”指的是什么? Notnull 表示该字段的值“null”是可接受的,而不是它的值将始终为 null,如果这是您的意思。

    【讨论】:

    • 我添加了固定装置,以便清楚地了解我的情况。如果我将 Notnull 设置为 false 只是为了避免出现“SQLSTATE[23000]:完整性约束违规:1048 列“default_edition_id”不能为空”的错误,则添加的每个新章节都将其 DefaultEdition 列设为 NULL;这是我不想要的。
    • @Dashed:好的,这样就更容易理解了。我目前正在阅读本教程:symfony-project.org/jobeet/1_4/Doctrine/en/03 如您所见,在夹具文件中,引用的类别是在引用作业之前定义的。我不知道这是否重要,但您可能想尝试在您的夹具文件中反转章节和版本部分...
    • 不,不管我把章节和版本装置放在什么顺序。
    • 如果您尝试仅加载 Edition 固定装置,记录看起来是否正常?他们有非空 id 吗?
    猜你喜欢
    • 2020-03-29
    • 2018-03-04
    • 2018-05-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-20
    相关资源
    最近更新 更多