Certain types of properties are unable to be automatically identified as a sequelize data type. It is necessary to manually specify the data type in order to

Creating a one-to-many relationship between a User and a Product using sequelize-typescript.

Below are the Models:

Product.ts

@Table
export class Product extends Model {
    @Column({ primaryKey: true })
    id!: string

    @Column
    title!: string

    @Column({ type: DataType.DOUBLE })
    price!: number

    @Column
    imageUrl!: string

    @Column
    description?: string

    @ForeignKey(() => User)
    @Column
    userId?: string

    @BelongsTo(() => User)
    user?: User
}

User.ts

@Table
export class User extends Model {
    @Column({ primaryKey: true })
    id!: string

    @Column
    name!: string

    @Column
    email!: string

    @Column
    @HasMany(() => Product)
    products?: Product[]
}

Encountering the error message below:

Specified type of property 'products' cannot be automatically resolved to a sequelize data type. Please define the data type manually

Here's the full stack trace:

*ProjectPath*/node_modules/sequelize-typescript/dist/model/shared/model-service.js:64
    throw new Error(`Specified type of property '${propertyName}'
          ^
Error: Specified type of property 'products'
            cannot be automatically resolved to a sequelize data type. Please
            define the data type manually
    at Object.getSequelizeTypeByDesignType (*ProjectPath*/node_modules/sequelize-typescript/dist/model/shared/model-service.js:64:11)
    at annotate (*ProjectPath*/node_modules/sequelize-typescript/dist/model/column/column.js:32:44)
    at Column (*ProjectPath*/node_modules/sequelize-typescript/dist/model/column/column.js:14:9)
    at DecorateProperty (*ProjectPath*/node_modules/reflect-metadata/Reflect.js:553:33)
    at Object.decorate (*ProjectPath*/node_modules/reflect-metadata/Reflect.js:123:24)
    at __decorate (*ProjectPath*/src/models/user.ts:4:92)
    at Object.<anonymous> (*ProjectPath*/src/models/user.ts:27:5)
    at Module._compile (internal/modules/cjs/loader.js:1156:30)
    at Module.m._compile (*ProjectPath*/node_modules/ts-node/src/index.ts:1043:23)
    at Module._extensions..js (internal/modules/cjs/loader.js:1176:10)

Any assistance on this matter would be highly appreciated.

Answer №1

The issue here lies in the fact that products is not a column within your table structure.

Instead, it is a property generated by Sequelize for locating associated models.

To resolve this problem, you must eliminate the @Column directive preceding products in your User model. Currently, Sequelize is attempting to treat it as a column present in your database table, when in reality it does not exist within your DB schema.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

PHP file containing an HTML input type tag

I am working on displaying a record from a database in a table using a PHP file. However, I am encountering an issue with a specific line of code that I need help with. This line of code involves using a checkbox to delete a row in the database. Here is t ...

In SQL, when you see two "@" symbols together, it typically signifies a special function or operation being performed within the query

The information I searched for wasn't included in the MySQL documentation. SELECT accesion_id, definition FROM accesion_table WHERE search_word @@ ? OFFSET ? LIMIT Const.MAX_DISP_COUNT; ...

What is the best way to obtain a client's IP address when utilizing our website through node js?

I attempted to obtain the IP address of a client's system using JavaScript on my website, but unfortunately, I was unsuccessful. I preferred not to rely on third-party websites like "" to retrieve this information. I am aware that this can be achieved ...

Tips for implementing custom string ordering with Sequelize

Seeking guidance on implementing custom order with Sequelize I'm attempting to organize an array of objects fetched from the database as ACTIVE, PENDING, INACTIVE Any suggestions or examples for accomplishing this using Sequelize? Attempted approac ...

Changing a double into the MySQL date format

Within my mysql database, there is a table called "students" with a column titled "runtime" that contains values such as 1381387683741 and 1381387683739. After using a converter, the results show: Thu, 10 Oct 2013 06:48:03 GMT My query is how I can ac ...

Navigating ExpressJS with Two MongoDB Collections Querying

I have successfully implemented a collection model that displays documents based on two properties in the URL path. When the URL contains /red/monday, for example, all images with those specific values are displayed. Now, I want to create a second collecti ...

How can Angular JS handle multiple validators being triggered at once?

Hey there, I'm currently working with validators in my Angular form setup. Here's a snippet of how it looks - I utilize Validators.compose to combine custom validators. The errors from these validators are then displayed on the HTML component. My ...

Unable to proceed with the deletion of records using a PHP query

I've been attempting to remove a record in HTML/PHP but have encountered issues. I've tried numerous times without success. Can anyone provide me with a solution? <?php while($row=mysqli_fetch_assoc($result)){ ?> <a href="delete.php?i ...

Sign up for notifications using NGRX

How can I incorporate CompanyEffects in my AppModule after receiving a response from the AppConfigService on the server? Effect registration within AppModule EffectsModule.forRoot([CompanyEffects]), CompanyEffects Implementation export class CompanyEff ...

Typescript controller inheritance leading to Error: $injector:unpr Unknown Provider due to minification

LATEST UPDATE: 2019/07/16 The issue I am facing is actually a result of misusing $inject. Instead of declaring it as private $inject in api-service.ts, it should have been public static $inject = [...]. During the minification process, explicit injection ...

Choosing a personalized component using document selector

Currently, I am working on an application using Stenciljs and have created a custom element like this: <custom-alert alertType="warning" alertId="warningMessage" hide>Be warned</custom-alert> The challenge arises when attem ...

Incorporating EJS Statements in a Simple HTML Document along with TypeScript

Trying to comprehend a seed project for Angular 2 which is quite complex, something caught my attention in the index.html file that I can't explain. There seems to be ejs statements included: <!-- src/client/index.html --> <title><%= A ...

Parameterized query causing JavaScript error

As I struggle with this issue for more than a day now, a scenario unfolds where a user clicks on a link of a book name triggering me to read that book's name. Subsequently, an Ajax request is made to a Jersey resource within which a method in a POJO c ...

The k6.io library is unable to read binary files using the TextDecoder file because of a problem with the util

For my k6.io tests, I am trying to import TextDecoder from the util package. Within my script, I aim to read a binary file: import { sleep, check } from 'k6'; import { Options } from 'k6/options'; import http from 'k6/http'; ...

Tips for accurately defining prop types in next.js when utilizing typescript?

Here is the content of my index.tsx file: import type { NextPage } from "next"; type AppProps = { articles: { userId: number; id: number; title: string; body: string; }; }; con ...

Using a UUID as the primary key in Sequelize results in the following error message: (node:6927) UnhandledPromiseRejectionWarning: SequelizeDatabaseError: Field 'id' must be provided with a value as it doesn't have

Although this issue is widely reported, it lacks proper documentation and the workarounds available are not very "professional" such as "Removing strict mode from MySQL". I am trying to set a uuidv4 as a primary key using sequelize in my app but I keep en ...

Properties undefined

All of my functions are giving errors indicating that the props are not defined. The error specifically relates to the word "props" in the following functions: function PostButton(props) function PostButton2(props) function TotalVotes(props) ...

Express is unable to provide static file hosting for a child EJS file

My current setup includes express version 3.2.5 and ejs version 0.8.4 I am looking to serve the stylesheet stylesheets/style.css In my app.js, I have implemented the following: app.use(express.static(path.join(__dirname, 'public'))); app.u ...

The TypeScript error arises when an element implicitly contains an 'any' type due to the inability to use an expression of type 'any' to index a specific type

Encountering an Issue: Element implicitly has an 'any' type because expression of type 'any' can't be used to index type '{ foo: string; bar: string; }'.ts(7053) Within the following code snippet: const CATEGORY_COLORS ...

Troubleshooting notifications generated by react-hook-form and zod

My customer registration form is causing all my error messages to show as "required." I suspect it might be a misconfiguration in zod or react-hook-form. Below, you'll find the code snippets. This is my generic input component: import { DetailedHTMLP ...