Comments (2)
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.
Should have been opened in cli project. Sorry.
from express-example.
Related Issues (20)
- How to use the transaction? HOT 1
- Add TypeScript Example HOT 2
- Add examples of associations HOT 1
- nodemon index.js doesn't work
- upsert route HOT 1
- Should the directory structure be updated to adapt to the directory structure of Sequelize CLI?
- Contributing and Maintaining information HOT 2
- dynamic imports do not work for defining models HOT 2
- "node_modules/.bin/sequelize" is not work on windows HOT 2
- Unit test hanging or sequelize doesn't close connection HOT 1
- enable Travis CI / Circle CI
- Why we need to define structure of database TWICE? HOT 8
- how to use DataType from req.body HOT 2
- npm install error HOT 4
- duplicate foreignKey when using sequelize.sync() HOT 3
- What does Model.associate() do in model/index.js ? HOT 4
- Please provide an example using sequelize v5 and TypeScript. HOT 6
- Update this repo HOT 3
- Stop using `sequelize.import` HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from express-example.