Redwood: Unknown database type on db save

Created on 13 Mar 2020  ·  12Comments  ·  Source: redwoodjs/redwood

While following along with the Tutorial, I got this error which is apparently due to the environment variable not getting loaded from .env.defaults:

$ yarn redwood db save
yarn run v1.22.0
$ ... redwoodblog/node_modules/.bin/redwood db save
Creating database migration... [started]
$ ... redwoodblog/node_modules/.bin/prisma2 migrate save --experimental
Error: Unknown database type
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Creating database migration... [failed]
→ Command failed with exit code 1: yarn prisma2 migrate save --experimental
Command failed with exit code 1: yarn prisma2 migrate save --experimental
✨ Done in 2.05s.

$ yarn -v
1.22.0
$ node -v
v12.14.0
"@redwoodjs/core": "^0.2.0"

If I change api/prisma/schema.prisma from this:

datasource DS {
  provider = "sqlite"
  url = env("DATABASE_URL")
}

...to this:

datasource DS {
  provider = "sqlite"
  url = "file:./dev.db"
}

...it works fine.

I see in the prisma2 docs, it mentions that the .env file has to be in the same directory as the schema file. But I assume that Redwood is meant to be handling the loading of environment variables differently, so that it's not necessary for the env file to be in the same directory.

bu0-needs-info

Most helpful comment

Would it make sense to try and render the DB info that Redwood is trying to use in the error message? That way it can give people a hint on where to look for when they have problems.

All 12 comments

Hi @paltamadura thanks for checking here and sorry for the hassle. Looping in @cannikin as he's the master of all things crazy-bleeding-edge-prisma-magic 🌟

Just yesterday we needed to make some changes to the env vars, which looks like it's updated in your example above. Here's the related PR:
https://github.com/redwoodjs/create-redwood-app/pull/33/files

Doing some checks on my end and then I’ll loop back.

No errors on my end locally.

@paltamadura can you confirm your OS and version?

macOS 10.14.6. @redwoodjs versions in yarn.lock are all 0.2.0. I posted yarn and node versions above. Any other ones?

I think that’s it. Thanks! Wish I had an easy solution here but no such luck.

This might take us a bit to diagnose. Are you ok to at least go through the tuturial with the workaround above?

Absolutely! Was just hoping to help others if they got stuck on it.

@paltamadura But you do have a .env.defaults with a DATABASE_URL in it, correct?

I added a log statement for process.env. The DATABASE_URL variable was set, but it didn't look right. I discovered it was coming from my profile. Once I removed it from my profile, yarn rw db save works as expected.

Would it make sense to try and render the DB info that Redwood is trying to use in the error message? That way it can give people a hint on where to look for when they have problems.

I had this issue as well when following the tutorial. I updated the .env.defaults file in root to replace DB_HOST=file:./dev.db -> DATABASE_URL=file:./dev.db and it fixed the issue.

MacOS Catalina
yarn 1.21.1
node 13.5

@TravisL12 it sounds like you might be on an older version of Redwood since we changed from DB_HOST to DATABASE_URL.

Would it make sense to try and render the DB info that Redwood is trying to use in the error message? That way it can give people a hint on where to look for when they have problems.

@peterp are you thinking about opening a separate Issue for this? (And/or did you already fix it somewhere? 'cause I know how you can get speedy with those merges 😉)

Closing — fixed in latest release.

Was this page helpful?
0 / 5 - 0 ratings