question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Relation fields are removed after npx prisma db pull

See original GitHub issue

Bug description

Virtual fields are removed after npx prisma db pull

How to reproduce

If you do npx prisma db pull the answers and candidate fields will be removed

Expected behavior

npx prisma db pull won’t remove virtual fields

Prisma information

generator client {
  provider        = "prisma-client-js"
  previewFeatures = ["referentialIntegrity"]
}

datasource db {
  provider     = "mysql"
  url          = env("DATABASE_URL")
  relationMode = "prisma"
}

model Answer {
  id          Int        @id @default(autoincrement())
  candidateId Int?       @map("candidate_id")
  candidate   Candidate? @relation(fields: [candidateId], references: [id])
  shortCode   String?    @map("short_code") @db.VarChar(10)

  @@map("answer")
}

model Candidate {
  id                Int       @id @default(autoincrement())
  shortCode         String?   @map("short_code") @db.VarChar(10)
  answers           Answer[]

  @@map("candidate")
}

Environment & setup

  • OS: macOS 12.4
  • Database: PlanetScale
  • Node.js version: v16.14.2

Prisma Version

prisma                  : 4.5.0
@prisma/client          : ^4.5.0
Current platform        : darwin-arm64
Query Engine (Node-API) : libquery-engine 0362da9eebca54d94c8ef5edd3b2e90af99ba452 (at ../../../.npm/_npx/2778af9cee32ff87/node_modules/@prisma/engines/libquery_engine-darwin-arm64.dylib.node)
Migration Engine        : migration-engine-cli 0362da9eebca54d94c8ef5edd3b2e90af99ba452 (at ../../../.npm/_npx/2778af9cee32ff87/node_modules/@prisma/engines/migration-engine-darwin-arm64)
Introspection Engine    : introspection-core 0362da9eebca54d94c8ef5edd3b2e90af99ba452 (at ../../../.npm/_npx/2778af9cee32ff87/node_modules/@prisma/engines/introspection-engine-darwin-arm64)
Format Binary           : prisma-fmt 0362da9eebca54d94c8ef5edd3b2e90af99ba452 (at ../../../.npm/_npx/2778af9cee32ff87/node_modules/@prisma/engines/prisma-fmt-darwin-arm64)
Format Wasm             : @prisma/prisma-fmt-wasm 4.5.0-43.0362da9eebca54d94c8ef5edd3b2e90af99ba452
Default Engines Hash    : 0362da9eebca54d94c8ef5edd3b2e90af99ba452
Studio                  : 0.476.0
Preview Features        : referentialIntegrity

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
NicolaGenesinJettycommented, Nov 3, 2022

Thank you so much! I love Prisma!

1reaction
NicolaGenesinJettycommented, Nov 2, 2022

@Jolg42 sorry, I’ve removed most fields to make it easy to read for you and missed that line.

These are the untouched tables

CREATE TABLE `answer` (
	`id` int NOT NULL AUTO_INCREMENT,
	`candidate_id` int,
	`short_code` varchar(10),
	`question_id` varchar(50),
	`request_json` json,
	`created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP(),
	`updated_at` datetime ON UPDATE CURRENT_TIMESTAMP(),
	`deleted` tinyint(1) NOT NULL DEFAULT '0',
	PRIMARY KEY (`id`)
) ENGINE InnoDB,
  CHARSET utf8mb4,
  COLLATE utf8mb4_0900_ai_ci;

and

CREATE TABLE `candidate` (
	`id` int NOT NULL AUTO_INCREMENT,
	`status` varchar(50),
	`full_name` varchar(100),
	`email` varchar(100),
	`phone_number` varchar(100),
	`linkedin_url` varchar(500),
	`contact_preference` varchar(10),
	`short_code` varchar(10),
	`request_json` json,
	`created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP(),
	`updated_at` datetime ON UPDATE CURRENT_TIMESTAMP(),
	`deleted` tinyint(1) NOT NULL DEFAULT '0',
	PRIMARY KEY (`id`),
	UNIQUE KEY `email` (`email`)
) ENGINE InnoDB,
  CHARSET utf8mb4,
  COLLATE utf8mb4_0900_ai_ci;
Read more comments on GitHub >

github_iconTop Results From Across the Web

Prisma CLI Command Reference
This page gives an overview of all available Prisma CLI commands, explains their options and shows numerous usage examples.
Read more >
Migration troubleshooting in development
This guide describes how to resolve issues with Prisma Migrate in a development environment, which often involves resetting your database.
Read more >
What is introspection? (Reference)
You can introspect your database using the prisma db pull command of the Prisma CLI. Note that using this command requires your connection...
Read more >
CRUD (Reference)
This page describes how to perform CRUD operations with your generated Prisma Client API. CRUD is an acronym that stands for: Create; Read;...
Read more >
Customize a migration file
To actually rename a field and avoid data loss when you run the migration in production, you need to modify the generated migration...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found