views:

251

answers:

1

I'm getting a weird error in symfony 1.4 with doctrine 1.2. My schemas seem to be normal. But whenever I execute the doctrine:build --all --no-confirmation --and-load task, it would output the error SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'default_edition_id' cannot be null. If I set notnull to false for the default_edition_id field, it would actually just be null. Can anyone help me out on what I may be missing?

Here is my schema file (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

and my edition schema (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

Fixtures:

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
A: 

"If I set notnull to false for the default_edition_id field, it would actually just be null". In this sentence, was does "it" refer to? Notnull means that the value 'null' is acceptable for this field, not that its value will always be null, if this was what you meant.

greg0ire
I added fixtures to a be a little clear on my situation. If I set Notnull to false just to avoid the error of 'SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'default_edition_id' cannot be null', each new chapter added would have its DefaultEdition column as NULL; which I do not want.
Dashed
@Dashed: Ok, that's far more understandable like this. I'm currently reading this tutorial : http://www.symfony-project.org/jobeet/1_4/Doctrine/en/03 As you can see, in the fixture file, the referenced categories are defined before the referencing job. I don't know if this matters or not, but you might want to try inverting the Chapter and Edition sections in your fixture file...
greg0ire
No, it doesn't matter what order I put the Chapter and Edition fixtures in.
Dashed
If you try loading the Edition fixtures only, do the records look fine? Do they have a not null id?
greg0ire