Hi, I'm new, but trying the tutorial and need help w/part 2 DB

I can’t get /posts to render the table. I don’t see how to correct this.

I’ve been just following along w/the video Tutorial for part 2

Overview

I am able to get to the point were I modify the schema and run the commands but they seem to work differently now.

I tried a few things but I’m not sure what I’m missing.

Here’s the repo after generating the db and running the scaffold command: Here it is, https://github.com/jacebenson/redwoodblog

Differences;

Commands work differently

  1. yarn rw db save - This asks questions in the tutorial but not for me and the output of files is slightly different (more below)
  2. yarn rw db up - This seems to not tie up the console in the tutorial but does for me.

More Details;

So @ 1:53 - RedwoodJS Tutorial, Part 2 - YouTube the schema is set up
Here’ my schema;

datasource DS {
  // optionally set multiple providers
  // example: provider = ["sqlite", "postgresql"]
  provider = "sqlite"
  url      = env("DATABASE_URL")
}

generator client {
  provider      = "prisma-client-js"
  binaryTargets = ["native", "rhel-openssl-1.0.x"]
}

// Define your own datamodels here and run `yarn redwood db save` to create
// migrations for them.
// TODO: Please remove the following example:
model Post {
  id        Int      @id @default(autoincrement())
  title     String
  body      String
  createdAt DateTime @default(now())
}

Then the command yarn rw db save is run which seems to ask these questions;

  • database Options yes/no.
  • name of migration

I don’t see either of these questions.
So I look at the file path and locally its;
/api/prisma/migrations/{{datetimestamp}}-migration
where on the video it shows
/api/prisma/migrations/{{datetimestamp}}-create-posts

I think, okay its different but the output stuff is similar. Lets just see if it works.
Next command yarn rw db up
This also seems to work differently in that on the video its run and done, returns the console to Rob. On mine my console never returns to me. It’s just running the whole time.

Here’s the output of the console

jaceb@home MINGW64 ~/git/redwoodblog
$ yarn rw db up
yarn run v1.22.5
$ C:\Users\jaceb\git\redwoodblog\node_modules\.bin\rw db up
Migrate database up... [started]
$ C:\Users\jaceb\git\redwoodblog\node_modules\.bin\prisma migrate up --experimental --create-db
Prisma Schema loaded from prisma\schema.prisma
migrate up

All migrations are already applied
Migrate database up... [completed]
Generating the Prisma client... [started]
$ C:\Users\jaceb\git\redwoodblog\node_modules\.bin\prisma generate
Prisma Schema loaded from prisma\schema.prisma

Okay, fine maybe it needs to run. New terminal.
So this is all fine still, cause the issue is I want to see the output from the scaffold command.

And it looks like redwood creates the right stuff, but when I navigate to localhost:8910/posts i get an error that something is wrong.

The yarn rw dev shows this output

$ yarn rw dev
yarn run v1.22.5
$ C:\Users\jaceb\git\redwoodblog\node_modules\.bin\rw dev
$ C:\Users\jaceb\git\redwoodblog\node_modules\.bin\webpack-dev-server --config ../node_modules/@redwoodjs/core/config/webpack.development.js
$ C:\Users\jaceb\git\redwoodblog\node_modules\.bin\dev-server
api | Running at 'http://localhost:8911'
api | Watching files in 'C:\Users\jaceb\git\redwoodblog\api\src\functions'
web | i 「wds」: Project is running at http://localhost:8910/
web | i 「wds」: webpack output is served from /
web | i 「wds」: Content not from webpack is served from C:\Users\jaceb\git\redwoodblog\web
web | i 「wds」: 404s will fallback to /index.html
api | Done. Took 2306ms.
api | POST /graphql 200 159.526 ms - 1009
api | POST /graphql 200 27.357 ms - 1009
api |
api | Error:
api | Invalid `prisma.post.findMany()` invocation in
api | C:\Users\jaceb\git\redwoodblog\api\src\services\posts\/posts.js:4:18
api |
api |
api |   Failed to validate the query: `Field does not exist on enclosing type.` at `Query.findManyPost`
api |
api |
api | 1 $w.request
api |   C:\Users\jaceb\git\redwoodblog\node_modules\@prisma\client\runtime\src\runtime\getPrismaClient.ts:1258
api |
api |
api | Error:
api | Invalid `prisma.post.findMany()` invocation in
api | C:\Users\jaceb\git\redwoodblog\api\src\services\posts\/posts.js:4:18
api |
api |
api |   Failed to validate the query: `Field does not exist on enclosing type.` at `Query.findManyPost`
api |
api |
api | 1 $w.request
api |   C:\Users\jaceb\git\redwoodblog\node_modules\@prisma\client\runtime\src\runtime\getPrismaClient.ts:1258
api |

I looked around on here and found some post that said to check if yarn rw db studio works and it seems to I can see the table columns and such.

I would love any feedback.

Oh other posts said to make a repo for it so yall could see the code.

Hi Jace, welcome to the forums :wave:

Sorry you’re having problems with the tutorial. Lots of things have happened with redwood since the video tutorials were recorded.

yarn rw db save takes the name of the migration as an option and no questions are asked when you run it now. So the command would be yarn redwood db save create posts. But it really shouldn’t matter. All that happens is you get an un-named migration.

yarn rw db up should still return to the terminal, as it does in the video. So something’s wrong there.

I notice you’re on Windows (so am I). What version of GitForWindows are you on? What node version do you have?

1 Like

Can you post or link the content of posts.js?

I assume you mean the redwoodblog/api/src/services/posts/posts.js

I have access to mac and windows. I’ll check those versions tonight.

Hmm just a hunch, I see it’s set to sqlite, do you have the env variable set for your database and did it create a file?

Default is DATABASE_URL=file:./dev.db

1 Like

Oh that might be it. When working with something else I know I made an environment variable with that name or similar. Again, I’ll check tonight.

1 Like

No environment variable with that name when I look.
On windows did a gci env:* | sort-object name


On git bash did a printenv,which has more, but no DATABASE_URL

I am on git version 2.27.0.windows.1
I am on node version 12.16.2
image

Is that file generated anywhere though? The env.default might work if you don’t have one set, but if there isn’t that db filename generated anywhere I’d say that might be the culprit. I’d add that and try to rerun yarn rw db up

Yeah I’d try adding that.

DATABASE_URL isn’t a system wide environment variable. It’s set in .env or .env.default. So check those files and see what you have there

I would also update your git and node versions. Especially the node version. I’ve heard others having problems with v12 on Windows.

Hope this helps :slight_smile:

Hi @jacebenson

I am coming in a little late to the game, but I noticed that the original post that the error is

This leads me to believe that:

  • connected to DB
  • but either no table
  • or no id column on table

I recommend:

  • Download TablePlus (works on Windows) and open the SQLite database as specified in your DATABASE_URL
  • Look for the tables and the columns there

Or

Launch the prisma studio via yarn rw db studio and look there.

If you

  • connect
  • see the Post table and that it has an id

If it has that then … not sure what it might be :wink: but can go from there.

If not, make sure the _Migration table is there (can only see in TablePlus as Prisma hides it) and your migrations have run.

I’m going to restart the tutorial, but this time I’ll record it and post to youtube. If I get the same problem, maybe it’ll be clear whats wrong.

yea I’m still having issues on windows. I’m sure its supposed to work but I’m not sure what’s different.
https://youtu.be/Bi0z364t3X8 (video is still processing for high def)

I looked at both yarn rw db studio (in video here: https://youtu.be/Bi0z364t3X8?t=755) I after this installed TablePlus and was also able to see the column id on table Post

Thanks for the videos. I’ll watch again but was wondering if these issues might be related:

Also @jacebenson I noticed that you are not (or not often) restarting ‘RW dev’

Not that it will make a difference but maybe something isn’t completely reloading based on changes?

Not likely but worth a shot to rule out.

Also:

When you get this this screen:

image

to view all the posts, can you:

  • Show the Developer Tools console for errors

  • Show the Developer tools network area for the graphql query

So can see what it is querying

{"variables":{},"query":"{\n  posts {\n    ...postFields\n    __typename\n  }\n}\n\nfragment postFields on Post {\n  id\n  title\n  body\n  createdAt\n  __typename\n}\n"}

  • Show code for your PostsCell (I think).

I saw you working with the env files, please see: Environment Variables | RedwoodJS Docs

The .env is hidden, but …

Technically, we use dotenv-defaults, which is how we also supply and load .env.defaults.

Here’s how I use:

  • .env.example - All envars needed but with blank values. This informs the developer everything they may need. Sometimes I add comments here as to which are web and which are api (since for web you will need to set them in toml). Note this file is checked into GH so you do not want any values that exposed secrets etc.

  • .env.defaults - Just the envars from .example that I am OK with setting as public values, if this is important to share with others. This informs the developer everything they may need and a valid value. Sometimes I add comments here as to which are web and which are api (since for web you will need to set them in toml). Note this file is checked into GH so you do not want any values that exposed secrets etc.

  • .env. Secrets. Vars you do not want to share with anyone. This can mimic prod or staging if needed. This is a hidden file and should never be checked in to GH.

Recently I have been using Doppler to manage across environments (prod, dev, staging, previews).

Yea, that’s… interesting. It looks like the two issues I think one linked to https://github.com/redwoodjs/redwood/issues/575
It looks like there was a commit to add a work around for windows.

It looks like the commit’s applied to fix this are still in the code;