sequelize / sequelize-typescript

Decorators and some other features for sequelize

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

After webpack confusion, As if the @foreignkey useless

Jarcem opened this issue · comments

Issue

i am using webpack5 to package the project, when the project runs the error was the primaryKey type is not the same as ForeignKey type, and i checked the final js file. the primaryKey type was the same as the foreignkey type. if i do not useing webpack project runs everything ok
there was system report

Referencing column 'items_uuid' and referenced column 'id' in foreign key constraint 'items_wallet_relationship_ibfk_279' are incompatible."

Versions

  • sequelize:6.28.0
  • sequelize-typescript:2.1.5
  • typescript:4.8.4
  • webpack:5.75.0

Issue type

  • bug report
  • feature request

Actual behavior

basic table association relationship

Expected behavior

project runs ok

Steps to reproduce

  1. table one
@Table({
    tableName: 'items'
})
export default class Items extends ModelExtension{
    @Column({
        primaryKey: true
    })
    uuid: string
    @ForeignKey(() => ItemsType)
    @Column({
    })
    type_id: number
    @Column({
    })
    item_name: string
    @Column({
    })
    item_img: string
    @Column({
      defaultValue: 0,
    })
    is_delete : number;
    @BelongsTo(() => ItemsType)
    itemsType: ItemsType
}
  1. table two
@Table({
    tableName: 'items_wallet_relationship'
})
export default class ItemsWalletRelationship extends ModelExtension{
    @Column({
        comment: 'id',
        autoIncrement: true,
        primaryKey: true
    })
    id: number
    
    @ForeignKey(() => Items)
    @Column({})
    items_uuid: string

    @ForeignKey(() => Wallet)
    @Column({})
    wallet_id: number

    @BelongsTo(() => Items)
    items: Items
    @BelongsTo(() => Wallet)
    wallet: Wallet
}

Related code

  1. webpack conf
'use strict';
const webpack = require('webpack');
const path = require('path');
var nodeExternals = require('webpack-node-externals');
module.exports = {
    entry: {
        app: [
            './dist/server.js'
        ]
    },
    output: {
        path: path.resolve(__dirname, './build'),
        filename: 'server.js'
    },
    target: 'node',
    externals: [nodeExternals()], 
    module: {
        rules: [
            {
                test: /\.js$/,
                use: ['babel-loader']
            }
        ],
    },
    resolve: {
        modules: [
            'node_modules',
            path.resolve(__dirname, 'dist'),
            path.resolve(__dirname, 'node_modules')
        ],
        extensions: [".js"]
    },
    plugins: [
    ]
};

  1. tsconf
{
  "compilerOptions": {
    "module": "commonjs",
    "esModuleInterop": true,
    "target": "ES2017",
    "noImplicitAny": true,
    "moduleResolution": "node",
    "sourceMap": true,
    "outDir": "dist",
    "baseUrl": ".",
    "paths": {
      "*": [
        "node_modules/*",
        "src/types/*"
      ]
    },
    "lib": [
      "es2017"
    ],
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "skipLibCheck": true,
    "types": ["node", "webpack-env"]
  },
  "include": [
    "src/**/*"
  ],
  "experimentalDecorators": true
}