OrwellHindenberg
OrwellHindenberg

Reputation: 5078

Unhandled Rejection SequelizeDatabaseError

I am working with Sequelize and I'm trying to insert one row into my User Column. However, I keep getting the following error:

Unhandled rejection SequelizeDatabaseError: Invalid object name 'User'.

I am connecting to a MSSQL server. I know that I have the basic connection right because I can run sequelize's plain queries via sequelize.query without issue. My suspicion is that I'm not specifying the schema or database correctly.

My model definition:

var user = sequelize.define("User", {
    ID: {
		type: Sequelize.INTEGER,
		unique: true,
		autoIncrement: true
	},
  	FirstName: {
		type: Sequelize.STRING
	},
	LastName: {
		type: Sequelize.STRING
	},
	CreateDate: {
		type: Sequelize.DATE
	},
	UpdateDate: {
		type: Sequelize.DATE
	}
},{
	tableName: 'User',
	timestamps: false,
	freezeTableName: true
});

My attempt to use the model to create/INSERT a row into my pre-existing database.

User.schema('Core');

User.create({ ID: '1', FirstName: 'Bobert', LastName: 'Jones'}).then(function(user) {
		console.log(user.get({
			plain: true
		}))
	});

When I used Sequelize's plain SQL to accomplish this I DID have to include the schema aka "insert into Core.User". Am I not specifying the schema correctly? I have tried adding it to my initial connection definition by adding "schema: 'Core'," before dialectOptions.

Upvotes: 1

Views: 7462

Answers (1)

scottjustin5000
scottjustin5000

Reputation: 1356

you can specify schema in your sequelize constructor:

var sequelize = new Sequelize("db",
    "user",
    "pass", {
        host: "localhost",
        port: "1206",
        dialect: "mssql",
        define: {
            schema: "core"
        }
    });

However, according to their code what you are doing appears correct. In the sequelize constructor you can also turn logging on (logging: true). Logging should output the exact sql that is being constructed.

Upvotes: 4

Related Questions