Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The table main.User does not exist in current database #18

Open
hyochan opened this issue Jun 6, 2024 · 5 comments
Open

The table main.User does not exist in current database #18

hyochan opened this issue Jun 6, 2024 · 5 comments

Comments

@hyochan
Copy link

hyochan commented Jun 6, 2024

I have followed the tutorial and face below issue while creating user.

The table `main.User` does not exist in the current database.]
 WARN  Possible Unhandled Promise Rejection (id: 4):
[PrismaClientKnownRequestError: 
Invalid `prisma.user.create()` invocation:


The table `main.User` does not exist in the current database.]

Migration done correctly, and extendedClient.user.useFindMany() is working.
However, when I try to create user, it shows above error.

await extendedClient.user.create({
  data: {
    id: 1,
    name: 'test',
  },
});

Below is my current sqlite status.
Screenshot 2024-06-06 at 11 38 35 AM

@sorenbs
Copy link
Member

sorenbs commented Jun 7, 2024

Hi Hyo,

Just to be sure - did you implement this step in your app?

import '@prisma/react-native';
import { PrismaClient } from '@prisma/client/react-native';

const baseClient = new PrismaClient();

async function initializeDb() {
  try {
    baseClient.$applyPendingMigrations();
  } catch (e) {
    console.error(`failed to apply migrations: ${e}`);
    throw new Error(
      'Applying migrations failed, your app is now in an inconsistent state. We cannot guarantee safety, it is now your responsibility to reset the database or tell the user to re-install the app'
    );
  }
}

@hyochan
Copy link
Author

hyochan commented Jun 13, 2024

I removed prisma folder and move files to root of the project and made it work!
However, app.db rows are not updated but strangely, the new row data is readable in app 🤔

@sorenbs
Copy link
Member

sorenbs commented Jun 17, 2024

Thank you for the update!

That's an understandable confusion. The app.db file in your repository is different from the app.db on the device or simulator. We should clear that up somehow. And we need to introduce a way to view the data on the device during development. Perhaps Prisma Studio could connect to the app over the network and red the on-device db that way. We'll figure something out.

Are we good to close this issue for now?

@mfucek
Copy link

mfucek commented Aug 8, 2024

I removed prisma folder and move files to root of the project and made it work! However, app.db rows are not updated but strangely, the new row data is readable in app 🤔

+1 on @hyochan's solution. I moved the scheme file, db, and migrations folder to the root (not the src) directory and got it working. This should be clarified in the readme.

@godwinmat
Copy link

godwinmat commented Sep 23, 2024

Does @prisma/react-native work with mongodb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants