Skip to content

Unclear Introspection error message: Error parsing attribute "@id": Fields that are marked as id must be required. #1368

Closed

Description

@janpio

Introspecting SQLite:

CREATE TABLE "playlist_track" (
	"PlaylistId"	INTEGER NOT NULL,
	"TrackId"	INTEGER NOT NULL,
	"id"	INTEGER PRIMARY KEY AUTOINCREMENT,
	FOREIGN KEY("PlaylistId") REFERENCES "playlists"("PlaylistId") ON DELETE NO ACTION ON UPDATE NO ACTION,
	FOREIGN KEY("TrackId") REFERENCES "tracks"("TrackId") ON DELETE NO ACTION ON UPDATE NO ACTION
)

Creates error message:

 ERROR  Oops, an unexpected error occured!
Schema parsing

error: Error parsing attribute "@id": Fields that are marked as id must be required.
  -->  schema.prisma:126
   |
125 |   TrackId    tracks
126 |   id         Int?      @id
   |

Error message does not include name of table/model for context.

Activity

  1. added
    bug/2-confirmed
    kind/bug
    on Jan 17, 2020
  2. added this to the Preview 21 milestone on Jan 17, 2020
  3. janpio commented on Jan 30, 2020

    @janpio
    ContributorAuthor

    Problem: No NOT NULL on id.

  4. modified the milestones: Preview 21, Preview 22 on Jan 31, 2020
  5. janpio commented on Feb 4, 2020

    @janpio
    ContributorAuthor

    Investigation into how SQLite works:

    Create a table with this SQL:

    CREATE TABLE "testing" (
    	"id"	INTEGER,
    	PRIMARY KEY("id")
    );
    

    Executing INSERT INTO testing (id) VALUES (NULL) creates a column with the id filled with the next auto increment value.

    Decision

    Integer PKs should therefore be inferred as Autoincrement NOT NULL.

  6. sorenbs commented on Feb 4, 2020

    @sorenbs
    Member

    For clarification:

    The consequence of inferring Integer PKs as Autoincrement NOT NULL (or as it would look like in the schema.prisma file: Int @id @default(autoincrement())) is that the id would be optional when writing, and non-null when reading.

    DECISION: this is excellent!

    See also prisma/specs#176 (comment) for context on autoincrement syntax.

  7. 15 remaining items

  8. tomhoule commented on Feb 11, 2021

    @tomhoule
    Contributor

    This will probably lead to an @@ignore on the model now, but work. To be confirmed.

  9. tomhoule commented on Feb 17, 2021

    @tomhoule
    Contributor

    Scheduling for this release to confirm that @@ignore fixes this.

  10. modified the milestones: 2.18.0, 2.19.0 on Mar 3, 2021
  11. modified the milestones: 2.19.0, 2.20.0 on Mar 17, 2021
  12. do4gr commented on Mar 18, 2021

    @do4gr
    Member

    This can only occur on SQLite since only there are optional id fields valid DDL. Models with an optional Id will now be marked as @@ignore during introspection and won't cause a validation error. If a model is handwritten with an optional id and without @@ignore, you'll still get the same validation error which is then clear enough.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug/2-confirmedkind/bugtopic: introspection

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions