Skip to content

Conversation

@drnic
Copy link
Contributor

@drnic drnic commented Oct 25, 2020

In the many-to-many photos/albums example - photo.views is required field

I was following through the tutorial using postgres, and my views column is defined as:

  @Column()
  views: number

Later, I was required to provide photo.views = 1 for the photo/albums example

drnic added 2 commits October 26, 2020 09:49
In the many-to-many photos/albums example - photo.views is required field
Fixes `null value in column "isPublished" violates not-null constraint`
@drnic drnic changed the title photo.views is required field photo.views/isPublished are required fields Oct 25, 2020
@imnotjames
Copy link
Contributor

imnotjames commented Oct 26, 2020

Where's that model defined? I can't find it in the README.

@imnotjames imnotjames self-requested a review October 26, 2020 02:37
@drnic
Copy link
Contributor Author

drnic commented Oct 26, 2020

The Photo model is the original class created in the tutorial https://github.com/typeorm/typeorm/blob/master/README.md#adding-table-columns

I'm using postgres, and typeorm created a photo table where each field/column was not null:

$ psql -U drnic typeorm_tutorial
psql (13.0, server 11.9)
Type "help" for help.

typeorm_tutorial=# \d photo
                                      Table "public.photo"
   Column    |          Type          | Collation | Nullable |              Default
-------------+------------------------+-----------+----------+-----------------------------------
 id          | integer                |           | not null | nextval('photo_id_seq'::regclass)
 name        | character varying(100) |           | not null |
 description | text                   |           | not null |
 filename    | character varying      |           | not null |
 views       | integer                |           | not null |
 isPublished | boolean                |           | not null |
 authorId    | integer                |           |          |
Indexes:
    "PK_723fa50bf70dcfd06fb5a44d4ff" PRIMARY KEY, btree (id)
Foreign-key constraints:
    "FK_c073d197b41cfbeb09835ca233c" FOREIGN KEY ("authorId") REFERENCES author(id)
Referenced by:
    TABLE "photo_metadata" CONSTRAINT "FK_99f01ed52303cc16139d69f7464" FOREIGN KEY ("photoId") REFERENCES photo(id)
    TABLE "album_photos_photo" CONSTRAINT "FK_d292b18c5fbb585c8ddb959ea81" FOREIGN KEY ("photoId") REFERENCES photo(id) ON DELETE CASCADE

Sorry if I've misread the tutorial and done something wrong to get to this point.

@drnic
Copy link
Contributor Author

drnic commented Oct 26, 2020

I guess the other solution is to originally introduce nullable earlier in the tutorial for these two fields?

  @Column({ nullable: true })
  views: number

  @Column({ nullable: true })
  isPublished: boolean

@pleerock
Copy link
Member

Change looks correct. Thank you!

@pleerock pleerock merged commit 3902fd1 into typeorm:master Oct 26, 2020
@imnotjames imnotjames added the hacktoberfest-accepted label hacktoberfest label Oct 26, 2020
dolsup pushed a commit to dolsup/typeorm that referenced this pull request Nov 3, 2020
* photo.views is required field

In the many-to-many photos/albums example - photo.views is required field

* photo.isPublished must be provided

Fixes `null value in column "isPublished" violates not-null constraint`
zaro pushed a commit to zaro/typeorm that referenced this pull request Jan 12, 2021
* photo.views is required field

In the many-to-many photos/albums example - photo.views is required field

* photo.isPublished must be provided

Fixes `null value in column "isPublished" violates not-null constraint`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

hacktoberfest-accepted label hacktoberfest

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants