Quantcast
Channel: Active questions tagged require - Stack Overflow
Viewing all articles
Browse latest Browse all 143

TypeError: Job.create is not a function

$
0
0

I'm using sequelize in my project, and importing the Job(variable connected to the database) from the models folder, but when I use Job.create it returns this error when inserting data into postman:TypeError: Job.create is not a function

I checked the connection with the database, and it's working, but Job.create doesn't work.code:

**//in models at Jobs.js file**const Sequelize = require('sequelize');const db = require('../db/connection');//Defineconst Job = db.define('job', {    title:{        type: Sequelize.STRING,    },    description:{        type: Sequelize.STRING    },    salary:{        type: Sequelize.STRING    },    company:{        type: Sequelize.STRING    },    email:{        type: Sequelize.STRING    },    new_job:{        type: Sequelize.INTEGER    }});
**// in routes at job.js file**const express = require('express');const router  = express.Router();const Job = require('../models/Job')//testrouter.get('/test',(req, res)=>{    res.send("As rotas estão funcionando");})//addrouter.post("/add", (req, res)=>{    let {title, salary, company, description, email, new_job} = req.body;    //insert     Job.create({        title,        salary,        company,        description,        email,        new_job    })    .then(()=>{        res.redirect('/');    })    .catch(err =>{        console.log(err);    });});module.exports = router;

Viewing all articles
Browse latest Browse all 143

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>