Himmators Himmators - 1 year ago 69
Node.js Question

belongsTo doesn't do anything

var Sequelize = require('sequelize');
var sequelize = new Sequelize('database', 'username', 'password', {
host: 'localhost',
dialect: 'sqlite',

// SQLite only
storage: 'db.sqlite'

var Driver = sequelize.define('driver', {
auth: Sequelize.STRING,
name: Sequelize.STRING,
phone: Sequelize.INTEGER,
bank: Sequelize.INTEGER,
idNo: Sequelize.STRING

var Hail = sequelize.define('hail', {
lat: Sequelize.INTEGER,
lon: Sequelize.INTEGER,


sequelize.sync().then(function() {
return Hail.create({
lat: 123,
lon: 1234
}).then(function(driver) {
plain: true

I'm trying to use the belongs to method to connect a hail to a driver. It doesn't seem to do anything. The log doesn't output any belongsTo field and hail doesn't have a driverID column in the database. I don't get any errors.

Answer Source

I suspect you've synced the database before adding the belongsTo call. The "sync" operation by default would not recreate the tables or modify the existing tables. You need to sync in a "force" manner once:

sequelize.sync({force: true}).then(function() {
    // ...

Note that this would destroy all the existing records you have in the tables.

Or, look into setting up the migrations.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download