prisma / react-native-prisma

Apache License 2.0
201 stars 9 forks source link

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

Open hyochan opened 5 months ago

hyochan commented 5 months ago

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 commented 5 months ago

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 commented 5 months ago

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 commented 5 months ago

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 commented 3 months ago

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 commented 2 months ago

Does @prisma/react-native work with mongodb