2021年2月10日星期三

ItemShops.create is not a function

I am trying to import a sequelize model from ItemShops.js, but am not sure how to reference the model to create an entry in the table.

In ItemShops.js:

module.exports =  function (sequelize, DataTypes) {  return sequelize.define('ItemShops', {      // Define attributes of ItemShops      item_id: {          type: DataTypes.INTEGER,          unique: true,          primaryKey: true,          autoincrement: false      },      item_name: {          type: DataTypes.STRING,      },      item_cost: {          type: DataTypes.INTEGER,      },      item_modifier: {          type: DataTypes.DECIMAL,      }}, {          timestamps: false,      });  };  

In dbinit.js:

    const Sequelize = require('sequelize');    // Create Sequelize instance  const sequelize = new Sequelize({      dialect: 'sqlite',      storage: './database.sqlite',      logging: false    });    // Check for successful connection to database  try {      sequelize.authenticate();      console.log('Connection has been established successfully.');    } catch (error) {      console.error('Unable to connect to the database:', error);    }    // Import table models from Users.js  const Users = require('./Models/Users')(sequelize, Sequelize);  const UserItems = require('./Models/UserItems')(sequelize, Sequelize);  const ItemShops = require ('./Models/ItemShops');    // Synchronize models to create tables  (async () => {      await sequelize.sync({ force: true }).then(function() {        return ItemShops.create ({item_id: 1, item_name: 'Apple', item_cost: 1, item_modifier: 0.5 });      });  })();  

When trying to run the dbint.js file, I get "ItemShops.create is not a function"

What am I doing wrong/missing?

https://stackoverflow.com/questions/66148627/itemshops-create-is-not-a-function February 11, 2021 at 12:07PM

没有评论:

发表评论