Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sequelize for Node.js : ER_NO_SUCH_TABLE

I'm new to sequelize and Node.js.
I coded for test sequelize, but error occured "ER_NO_SUCH_TABLE : Table 'db.node_tests' doesn't exist"
Error is very simple.
However, I want to get data from "node_test" table.
I think sequelize appends 's' character.

There is my source code.

var Sequelize = require('sequelize');

var sequelize = new Sequelize('db', 'user', 'pass');
var nodeTest = sequelize.define('node_test',
        { uid: Sequelize.INTEGER 
         , val: Sequelize.STRING} );

nodeTest.find({where:{uid:'1'}})
    .success(function(tbl){
        console.log(tbl);
    });

I already create table "node_test", and inserted data using mysql client.

Does I misunderstood usage?

like image 855
Minkyu Kim Avatar asked Dec 22 '12 11:12

Minkyu Kim


People also ask

How to establish connection between MySQL and nodeJS using Sequelize?

To establish connection between MySQL and Node.js using Sequelize, visit How to use Sequelize in Node.js. SequelizeDemo>app.js which is our root file. SequelizeDemo>utils>database.js which is responsible for MySql connection. SequelizeDemo>models>user.js which is responsible for defining the model.

Do I need to learn SQL to use Sequelize?

No need to learn SQL – queries are written in plain JavaScript. Sequelize needs MySql module installed in your project. if you have not installed MySql module then make sure before installing Sequelize you need to install MySql2 module. You need to install this module by using the following command.

How do I install Sequelize on Linux?

Installing Sequelize Begin by creating a project folder. In this example, you can use hello-world. Once the folder is created, navigate to the folder using the terminal: mkdirhello-world cdhello-world Then, create a sample Node.js application using the following command: npminit

What is Sequelize Orm?

Sequelize is a promise-based Node.js ORM for Postgres, MySQL, MariaDB, SQLite, and Microsoft SQL Server. Its features are solid transaction support, relations, eager and lazy loading, read replication and many more.


2 Answers

I found the answer my own question.

I appended Sequelize method option following. {define:{freezeTableName:true}}

Then sequelize not appends 's' character after table name.

like image 189
Minkyu Kim Avatar answered Sep 19 '22 23:09

Minkyu Kim


Though the answer works nicely, I nowadays recommend the use of the tableName option when declaring the model:

sequelize.define('node_test', { 
  uid: Sequelize.INTEGER,
  val: Sequelize.STRING
}, {
   tableName: 'node_test'
});

http://docs.sequelizejs.com/manual/tutorial/models-definition.html

like image 35
sdepold Avatar answered Sep 18 '22 23:09

sdepold