Comments (6)
Here is the prisma/seed.ts file:
import { PrismaClient } from "@prisma/client";
import bcrypt from "bcryptjs";
const prisma = new PrismaClient();
async function seed() {
const email = "[email protected]";
// cleanup the existing database
await prisma.user.delete({ where: { email } }).catch(() => {
// no worries if it doesn't exist yet
});
const hashedPassword = await bcrypt.hash("racheliscool", 10);
const user = await prisma.user.create({
data: {
email,
password: {
create: {
hash: hashedPassword,
},
},
},
});
await prisma.note.create({
data: {
title: "My first note",
body: "Hello, world!",
userId: user.id,
},
});
await prisma.note.create({
data: {
title: "My second note",
body: "Hello, world!",
userId: user.id,
},
});
const posts = [
{
slug: "my-first-post",
title: "My First Post",
markdown: `
# This is my first post
Isn't it great?
`.trim(),
},
{
slug: "90s-mixtape",
title: "A Mixtape I Made Just For You",
markdown: `
# 90s Mixtape
- I wish (Skee-Lo)
- This Is How We Do It (Montell Jordan)
- Everlong (Foo Fighters)
- Ms. Jackson (Outkast)
- Interstate Love Song (Stone Temple Pilots)
- Killing Me Softly With His Song (Fugees, Ms. Lauryn Hill)
- Just a Friend (Biz Markie)
- The Man Who Sold The World (Nirvana)
- Semi-Charmed Life (Third Eye Blind)
- ...Baby One More Time (Britney Spears)
- Better Man (Pearl Jam)
- It's All Coming Back to Me Now (Céline Dion)
- This Kiss (Faith Hill)
- Fly Away (Lenny Kravits)
- Scar Tissue (Red Hot Chili Peppers)
- Santa Monica (Everclear)
- C'mon N' Ride it (Quad City DJ's)
`.trim(),
},
];
for (const post of posts) {
await prisma.post.upsert({
where: { slug: post.slug },
update: post,
create: post,
});
}
console.log(`Database has been seeded. 🌱`);
}
seed()
.catch((e) => {
console.error(e);
process.exit(1);
})
.finally(async () => {
await prisma.$disconnect();
});
from examples.
@twobyte Did you create a migration first?
npx prisma migrate dev
from examples.
@MichaelDeBoey yes I did, it says Already in sync, no schema change or pending migration was found.
In fact, I tried the recommendations on this page yesterday before posting, but it hasn’t helped.
https://www.prisma.io/docs/guides/database/developing-with-prisma-migrate/troubleshooting-development
I see there is an update available for Prisma, will try that now 4.3.1 -> 4.4.0
from examples.
Still no luck using Prisma v4.4 I’m afraid. I tried npx prisma migrate reset
again and still same error.
I feel like I must be missing something very simple about registering the Post property to the PrismaClient – but I cannot see what! The model is listed in prisma/schema.prisma file, where else must it be registered to be able to seed?
Or could there be an issue with my Typescript environment?
The error again:
TSError: ⨯ Unable to compile TypeScript:
prisma/seed.ts:81:18 - error TS2339: Property 'post' does not exist on type 'PrismaClient<PrismaClientOptions, never, RejectOnNotFound | RejectPerOperation | undefined>'.
81 await prisma.post.upsert({
~~~~
at createTSError (/Remix/blog-tutorial/node_modules/ts-node/src/index.ts:859:12)
at reportTSError (/Remix/blog-tutorial/node_modules/ts-node/src/index.ts:863:19)
at getOutput (/Remix/blog-tutorial/node_modules/ts-node/src/index.ts:1077:36)
at Object.compile (/Remix/blog-tutorial/node_modules/ts-node/src/index.ts:1433:41)
at Module.m._compile (/Remix/blog-tutorial/node_modules/ts-node/src/index.ts:1617:30)
at Module._extensions..js (node:internal/modules/cjs/loader:1180:10)
at Object.require.extensions.<computed> [as .ts] (/Remix/blog-tutorial/node_modules/ts-node/src/index.ts:1621:12)
at Module.load (node:internal/modules/cjs/loader:1004:32)
at Function.Module._load (node:internal/modules/cjs/loader:839:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12) {
diagnosticCodes: [ 2339 ]
}
An error occured while running the seed command:
Error: Command failed with exit code 1: ts-node --require tsconfig-paths/register prisma/seed.ts
from examples.
I have posted the code here:
https://github.com/twobyte/remix-tutorial
Does this code work for anyone else?
from examples.
Well that is the strangest thing. It looks like prisma/schema.prisma
was not even saving my changes! I had to commit to the repo to see this.
Not sure if this was me being really dumb (pretty sure I saved the file many times) or an issue with VSCode not updating. In any case, this issue is resolved. Thank you for your time/attention and all your hard-work developing Remix.
from examples.
Related Issues (20)
- _official-realtime-app example is buggy HOT 3
- Using template as specified does not seem to work HOT 4
- Infinite scrolling example seems to be broken in codesandbox
- Emotion example is outdated HOT 2
- Cookie but missing user in db, ends up being a promise and not redirecting to login HOT 2
- [Feature Request] Framework user wants to have an example integration with Cloudscape Design System HOT 1
- _official-realtime-app Concurrent connections HOT 1
- tailwind styles are not processed in v1.19.2 but are in v1.19.1 HOT 1
- chakra-ui example has hydration issues HOT 2
- Stitches example: Greedy regexp pattern potentially breaks markup HOT 1
- MSW example not working HOT 1
- mdx-bundler example
- Example for Vite + Styled Components?? HOT 1
- Vite + Styled Components Example HOT 4
- Create an example of an app with nested routes
- nprogress uses useTransition, should it use useNavigation instead? HOT 2
- Feature: Pocketbase Auth Example with Realtime Data
- Stripe HOT 1
- sharing-loader-data example choice justification
- Transforming the `socket` example using `vite`
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from examples.