Giter Site home page Giter Site logo

Comments (2)

bahuy5696 avatar bahuy5696 commented on May 25, 2024 5

Should have been opened in cli project. Sorry.

I'm new in Node and also sequelize, can anyone help me with that.
I'll send my files but the config.json and config.js.
I'm getting this error during the execution of sequelize db:migrate:

sequelize db:migrate

Sequelize CLI [Node: 12.18.1, CLI: 5.5.1, ORM: 5.21.13]

Loaded configuration file "config/config.js".
Using environment "development".
== 20200622031102-create_package_table: migrating =======

ERROR: sequelize is not defined

this is my models/index.js
`'use strict';

const fs = require('fs');
const path = require('path');
const Sequelize = require('sequelize');
const basename = path.basename(__filename);
const env = process.env.NODE_ENV || 'development';
const config = require(__dirname + '/../../config/config.json')[env];
const db = {};

console.log('Iniciando sequelize!!!!');

var sequelize;
if (config.use_env_variable) {
//sequelize = new Sequelize(process.env[config.use_env_variable], config);
sequelize = new Sequelize(process.env["development"], config);
console.log('sequelizeCriado');
} else {
sequelize = new Sequelize(config.database, config.username, config.password, config);
}

fs
.readdirSync(__dirname)
.filter(file => {
return (file.indexOf('.') !== 0) && (file !== basename) && (file.slice(-3) === '.js');
})
.forEach(file => {
const model = sequelize['import'](path.join(__dirname, file));
db[model.name] = model;
});

Object.keys(db).forEach(modelName => {
if (db[modelName].associate) {
db[modelName].associate(db);
}
});

sequelize
.authenticate()
.then(() => {
console.log("Connection has been established succesfully");
})
.catch((err) => {
console.log("Unable to connect to the database:", err);
});

db.sequelize = sequelize;
db.Sequelize = Sequelize;

module.exports = db;
global.sequelize = db.sequelize;
`

this is one of my models package.js

`const db = require('.');

'use strict';

module.exports = (sequelize, DataTypes) => {
var Package = sequelize.define('Package', {
id: {
type: sequelize.BIGINT,
allowNull: false,
primaryKey: true,
autoIncrement: true
},
name: {
type: sequelize.STRING,
allowNull: false
},
creationDate: {
type: sequelize.DATE,
allowNull: false,
field: "createdAt"
},
tackingCode: {
type: sequelize.STRING,
allowNull: false,
field: "tackingCode",
validate: {
len: [13, 13],
is: ["^[A-Z]{2}[1-9]{9}[A-Z]{2}$", 'i']
}
},
isDelivered: {
type: sequelize.BOOLEAN,
allowNull: false,
defaultValue: true,
field: "isDelivered"
}

}, {
tableName: 'Packages',
sequelize,
modelName: 'Package',
timestamps: true
});
Package.associate = function (models) {
models.Package.hasMany(models.PackageCheck, {
onDelete: "CASCADE",
foreignKey: {
allowNull: false
}
});

};
return Package;
};`
It seems that the index.js is not running in the migration process.

How to fix this error man ??

from express-example.

magacho avatar magacho commented on May 25, 2024

Should have been opened in cli project. Sorry.

from express-example.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.