NextJS 16, Sequelize 6.37, TypeScript 5, SQL issues #189011
Replies: 3 comments 3 replies
-
|
Most likely the field name is mismatched, the fact that only ID, CREATEDAT, and UPDATEDAT get inserted (these are typically auto-generated) while all form fields come through as undefined strongly suggests your form field names don't match what your model/query expects. This is especially common with Oracle since column names are case-sensitive in how you define them in your ORM.
If this was helpful please mark it as answered. Thank you! |
Beta Was this translation helpful? Give feedback.
-
|
All three issues likely trace back to the same root cause: your form field values aren't reaching your Sequelize model. Here's how to diagnose each one: Issue 1 —
// In your model definition
firstName: {
type: DataTypes.STRING,
field: 'FIRST_NAME' // maps camelCase to Oracle uppercase column
}Issue 2 — const record = await MyModel.findOne({ where: { id } });
return <MyComponent data={record.toJSON()} />; // or: JSON.parse(JSON.stringify(record))Dates specifically will also need conversion since Issue 3 — // Next.js 15+
const { id } = await params;Posting your model definition and the route/action where the insert happens would help narrow it down further, but the above covers the most likely causes for each symptom. |
Beta Was this translation helpful? Give feedback.
-
|
Hey Fred, these three issues are all connected to the same root cause — Sequelize isn't mapping your form fields to the correct Oracle column names. Let me go through each one. The core problem: Oracle column name mapping in Sequelize Oracle stores column names in uppercase by default. Sequelize doesn't handle this automatically, so you need to explicitly tell it which JavaScript field maps to which Oracle column using the Without this, Sequelize silently fails to map the values — which is exactly why only Here's what your model should look like: import { DataTypes, Model } from 'sequelize';
class YourModel extends Model {}
YourModel.init(
{
id: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true,
field: 'ID',
},
firstName: {
type: DataTypes.STRING,
allowNull: false,
field: 'FIRSTNAME', // maps JS camelCase → Oracle uppercase
},
lastName: {
type: DataTypes.STRING,
allowNull: false,
field: 'LASTNAME',
},
createdAt: {
type: DataTypes.DATE,
field: 'CREATEDAT',
},
updatedAt: {
type: DataTypes.DATE,
field: 'UPDATEDAT',
},
},
{
sequelize,
tableName: 'YOUR_TABLE', // Oracle table names are uppercase too
timestamps: true,
}
);Once this is in place, all three issues should start making more sense. Issue 1 — "Cannot insert NULL" Before touching anything else, add this log right before your insert: console.log('req.body:', req.body);
console.log('mapped fields:', {
firstName: req.body.firstName,
lastName: req.body.lastName,
// add all your fields here
});If the values show up in Issue 2 — "Only plain objects can be passed to Client Components" This is a Next.js serialization issue at the Server/Client boundary. Date objects can't be passed directly — convert them to ISO strings before returning from your server component or API route: const record = await YourModel.findOne({ where: { id } });
return {
...record.toJSON(),
createdAt: record.createdAt?.toISOString() ?? null,
updatedAt: record.updatedAt?.toISOString() ?? null,
};Then on the client side, convert back when needed: const date = new Date(props.createdAt);Issue 3 — This means the First, check how you're getting the ID — in Next.js 15+, route params are now async: // Next.js 15+ — params is a Promise
const { id } = await params;
// older versions
const { id } = params;Second, make sure the ID actually exists before running the query: if (!id) {
throw new Error('ID is missing');
}
const record = await YourModel.findOne({
where: { id },
});This prevents Sequelize from even attempting the query with an undefined value. Start with fixing the model |
Beta Was this translation helpful? Give feedback.
-
|
If all the form fields are showing as A few things to check:
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Body
I posted a similar question on these issues, but decided to start a new discussion.
Issue 1: All required form fields are filled out, but output says: "... cannot insert NULL into..."
Issue 2: "Only plain objects can be passed to Client Components..." perhaps a date format conversion could be the reason?
Issue 3: "...Error: WHERE parameter "ID" has invalid "undefined" value
What I tried: Changed all model fields to uppercase (Oracle), removed the not null constraint - in this case the insert worked, but only the ID, CREATEDAT and UPDATEDAT fields were filled. I understand that the model must match the table columns in the database.
All affected form fields are UNDEFINED in the output.
Before posting the code maybe somebody knows already how to fix this?
Thanks!
Guidelines
Beta Was this translation helpful? Give feedback.
All reactions