Make sure Prisma is correctly configured to connect to your Azure SQL database. For that, you need to set the connection string in the .env
file.
DATABASE_URL="sqlserver://<USERNAME>:<PASSWORD>@<SERVER_NAME>.database.windows.net:1433;database=<DB_NAME>;encrypt=true;trustServerCertificate=false"
Replace:
-
<USERNAME>
: Your Azure SQL database username. -
<PASSWORD>
: Your password. -
<SERVER_NAME>
: The name of your Azure SQL server. -
<DB_NAME>
: The database name.
Ensure Prisma is installed:
npm install @prisma/client
You'll also need the Prisma CLI for schema management and migrations:
npm install prisma --save-dev
In your prisma/schema.prisma
file, make sure your model for the gymOwners
table is correctly set up according to your database schema.
Example schema.prisma
:
datasource db {
provider = "sqlserver"
url = env("DATABASE_URL")
}
generator client {
provider = "prisma-client-js"
}
model GymOwner {
id Int @id @default(autoincrement())
fullName String
phoneNo String
gymName String
gymAddress String
images String
subscriptionPackages String
gymContactInfo String
workoutsOffered String?
equipmentsAvailable String?
ledger_start_transaction_id BigInt
ledger_start_sequence_number BigInt
}
Generate the Prisma client and apply migrations to your database:
npx prisma migrate dev --name init
This will generate the required SQL and apply it to your Azure SQL database.
Your API route seems mostly correct, but make sure the endpoint URL used in your frontend is correct. Ensure the API URL is valid (you had a small typo):
const res = await axios.post("/api/v1/gymowners", formData);
Make sure you're using relative URLs ("/api/v1/gymowners"
) unless you need to specify an absolute path.
Your handleSubmit
function should successfully submit form data. Ensure that the field names match exactly what you’re expecting on the server.