0

I'm trying to connect to my SqlServer with Prisma. When i try to "prisma db pull" im getting this error.

P4001 The introspected database was empty

Of course my db is not empty. These are my connection string(database, user and password is true) and schema.prisma;

Connection String at .env:

DATABASE_URL="sqlserver://192.168.1.86;database=***_live_IT;user=***;password=***;encrypt=DANGER_PLAINTEXT;"

schema.prisma:

generator client {
  provider = "prisma-client-js"
}

datasource db {
  provider = "sqlserver"
  url      = env("DATABASE_URL")
}

And here is my SqlServer Tables(i want to connect ***_live_IT)

SQLServer Databases

And here is Tables of that Database

SQLServer Tables

Any idea is appreciated. Thanks in advance.

Edit: Full text of error here.

PS D:\xampp\htdocs\noip> npx prisma db pull
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
Prisma schema loaded from prisma\schema.prisma
Environment variables loaded from .env
Datasource "db" - SQL Server

✖ Introspecting based on datasource defined in prisma\schema.prisma
Error: 
P4001 The introspected database was empty:

prisma db pull could not create any models in your schema.prisma file and you will not be able to generate Prisma Client with the prisma generate command.

To fix this, you have two options:

- manually create a table in your database.
- make sure the database connection URL inside the datasource block in schema.prisma points to a database that is not empty (it must contain at least one table).

Then you can run prisma db pull again.
samiyilmaz
  • 1
  • 1
  • 4
  • You haven't posted any useful information like logs, the full error and stack trace. The linked image shows databases, not tables. As far as anyone knows, your database really doesn't have any tables. Or those tables [aren't in the `dbo` schema](https://github.com/prisma/prisma/issues/2983). Or the account [has no permission to read the database schema](https://github.com/prisma/prisma/issues/3041). Have you googled the error message? There are [similar questions](https://stackoverflow.com/questions/62913433/prisma-1-to-2-migration-issue-p4001-the-introspected-database-was-empty) – Panagiotis Kanavos Jul 19 '22 at 08:54
  • @PanagiotisKanavos yes i did upload only databases and not tables, sorry. I've updated my question, added my table's img. Yes i did search really hard and found nothing. The account that im using is system admin so i have all permissions. – samiyilmaz Jul 19 '22 at 09:09

2 Answers2

1

I solved this problem in a simple way.

prisma db push

then

prisma db pull
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
0

adding "schema=<schema_name>" to the database url solved this for me when trying to connect to a local sqlserver. Unfortunately, prisma can only connect to one schema at a time.