Reputation: 11
I need to know why my code isn't working. I'm trying to make a cart table which is going to have a foreign key userId and productId. To achieve that, in my product model and user I do what I follow:
User.hasMany(Car,{
primaryKey:'userId'
})
module.exports=User;
Product.hasMany(Car,{
primaryKey:'productId'
})
module.exports = Product;
in Car model I have:
const {Model, DataTypes}=require('sequelize');
const sequelize=require('../config/database');
const Product=require('./Product');
const User=require('./User');
class Car extends Model{}
Car.init({
id:{
primaryKey:true,
allowNull:false,
type:DataTypes.UUID,
defaultValue:DataTypes.UUIDV1
}
},{
sequelize,
modelName: 'car'
});
module.exports=Car;
I'm getting this mistake:
I need help.
Upvotes: 1
Views: 142